Solved

pointer tutorial ???

Posted on 2001-06-12
12
262 Views
Last Modified: 2010-04-02
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
Comment
Question by:deschenesp
12 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 6181573
See http://www.experts-exchange.com/jsp/qShow.jsp?ta=cplusprog&qid=20133833 and delete this one to have your points refunded...
0
 

Expert Comment

by:irisistable
ID: 6181629
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
 
LVL 14

Expert Comment

by:AlexVirochovsky
ID: 6181794
Write your EMail and I 'll send you Pointer tutorial
0
 
LVL 3

Expert Comment

by:ruff_ryder
ID: 6181801
For a tutorial on pointers check www.codeproject.com and look in the tutorials section
0
 
LVL 4

Expert Comment

by:prashant_n_mhatre
ID: 6181868
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
 
LVL 30

Expert Comment

by:Axter
ID: 6182150
prashant_n_mhatre,
Two of your posted links, are exactly the same.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 30

Expert Comment

by:Axter
ID: 6182151
prashant_n_mhatre,
Two of your posted links, are exactly the same.
0
 
LVL 4

Expert Comment

by:prashant_n_mhatre
ID: 6182180
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
 
LVL 1

Expert Comment

by:yabelson
ID: 6193153
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
 
LVL 43

Expert Comment

by:TimCottee
ID: 6231474
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
 
LVL 11

Expert Comment

by:griessh
ID: 6817237
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
 
LVL 5

Accepted Solution

by:
Netminder earned 0 total points
ID: 6833308
Per recommendation points refunded and question closed.

Netminder
Community Support Moderator
Experts Exchange
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now