• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 275
  • Last Modified:

pointer tutorial ???

Hi,

     Could someone explain to me why should I use pointer. Why would I want to know for example the memory adress of a variable (&c1). What's  so impressive about pointer and why should I use them ??????

      Sorry for that long question.
0
deschenesp
Asked:
deschenesp
1 Solution
 
jkrCommented:
See http://www.experts-exchange.com/jsp/qShow.jsp?ta=cplusprog&qid=20133833 and delete this one to have your points refunded...
0
 
irisistableCommented:
some of the nice things that you can do with pointers :
as you know, a function can have only one return value. a function cannot, for example, return a success/failure status and at the same time return a 'real' value (calculation result, some kind of string or whatever). you can solve the problem with global variables, but that it ugly and unsafe. with pointers, you can send to a function parameters which are actually addresses of variables, and the function can fill those addresses with data, which you can read later, when the function returns. so you have multiple returned values from a function.

another thing is scanning arrays - doing it with a pointer is faster than doing it with indexes.

a third thing is passing structs as parameters to functions. a struct 9or an object in C++) may be very large, and passing it by value will catch a lot of memory on the stack. passing a pointer is no more than 2/4 bytes...

and a very important usage of pointers is the dynamic allocation of arrays. you do not always know in advance the size of an array that you will need (for example - an array to hold the grades of students in a class. you don't know the number of students that will be when the program is run. if you 'hard code' an array of a specific it will probably be too big - memory wasted or too small - not enough room for all grades). with a pointer and a dynamic allocation during run-time you solve the problem.

there are many more reasons, but maybe you are already aware of the importance of pointers.
0
 
AlexVirochovskyCommented:
Write your EMail and I 'll send you Pointer tutorial
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
ruff_ryderCommented:
For a tutorial on pointers check www.codeproject.com and look in the tutorials section
0
 
prashant_n_mhatreCommented:
All information is here:

http://www.gator.net/~garyg/C/CONCEPT/pointers.html
http://pw1.netcom.com/~tjensen/ptr/pointers.htm
http://pw1.netcom.com/~tjensen/ptr/pointers.htm

Keep following things in mind while learning pointers whenever u see any expression.

address = address
value = value

and A[i] = *(A + i)
   A[i][j] = *(A[i] + j) = *(*(A+i) + j))
   A[i][j][k] = *(A[i][j] + k)
              = *(*(A[i] +j ) + k))
              and so on.......

Thanks and Best Regards,
PRASHANT.
0
 
AxterCommented:
prashant_n_mhatre,
Two of your posted links, are exactly the same.
0
 
AxterCommented:
prashant_n_mhatre,
Two of your posted links, are exactly the same.
0
 
prashant_n_mhatreCommented:
Thanks Axter,
It is because of 'copy and paste'funda.
The third link is
http://www.eecis.udel.edu/~long/181/Stanford_CSE_Library/102/PointersAndMemory.pdf
0
 
yabelsonCommented:
actually,we dont REALY need pointers,but they make our lives as programmers alot easier.
for ex.:if you have an array of 10 items(or whatever),nad you want to go to each one in any time,you can go by calling the name of the array and adding the place of the wanted item.the NAME of this array,is actually the name you have (unawer)gave to a pointer,who points to the address where this array starts.so when you go to the item,you realy go to the X places after the beginning address.
when you dont want to burden(overload,i forgot how to write it) the computer,you can use DYNAMIC memory.this will alow you to move freely around the items,AND(the most important thing!!)-you dont have to know the size of the array at beginning of your program!!
say,you awnt to get some names,but you dont know how many names you are going to get.you can use a dynamic array,and then add each name as you go along.but since you dont realy know where this array seats,you need something to point out to you the starting point of the array,so when you want to do something with these names,you can get to them.so you define a pointer,which you later give a value,and TIHS pointer is the thing that makes you go wherever you want in this array,just as if it was a normal array...
KAPISH?
0
 
TimCotteeCommented:
Sorry guys to hijack this thread but deschenesp has a number of outstanding ungraded questions, specifically of interest to me is http://www.experts-exchange.com/jsp/qShow.jsp?ta=vbdatabases&qid=11272334 this has been outstanding for more than 6 months.

deschenesp, failure to maintain your questions may be considered sufficient grounds for suspension of your account. I strongly suggest that you clean up the outstanding questions as soon as possible.
0
 
griesshCommented:
I think you forgot this question. I will ask Community Support to close it unless you finalize it within 7 days. Unless there is objection or further activity,  I will suggest to refund the points PAQ at zero points since your question was alredy answered in http://www.experts-exchange.com/jsp/qShow.jsp?ta=cplusprog&qid=20133833 .

The link to the Community Support area is: http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
======
Werner
0
 
NetminderCommented:
Per recommendation points refunded and question closed.

Netminder
Community Support Moderator
Experts Exchange
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now