any articles or books about pointer?

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Oct 2008
Posts: 18
Reputation: panpanf is an unknown quantity at this point 
Solved Threads: 0
panpanf's Avatar
panpanf panpanf is offline Offline
Newbie Poster

any articles or books about pointer?

 
0
  #1
Oct 19th, 2008
i am confused by pointers. How do we know the type the pointer points? Is it compiler specific? how do we implement delete[]? Are there any books or articles about this topic? Wait for your replies.
I am from China. I love computer science!
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,462
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1476
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: any articles or books about pointer?

 
1
  #2
Oct 19th, 2008
Seek and thou shalt find.

>>How do we know the type the pointer points?
You have to declare the data type when the pointer is created. int* iPointer;
>>Is it compiler specific?
No. Pointers are defined by C and C++ standards, so all compilers comply.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 118
Reputation: chococrack is on a distinguished road 
Solved Threads: 14
chococrack's Avatar
chococrack chococrack is offline Offline
Junior Poster

Re: any articles or books about pointer?

 
1
  #3
Oct 19th, 2008
Here's a silly little illustration I drew just now:
Attached Thumbnails
pointer_illustration.jpg  
I would love to change the world, but they won't give me the source code
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 675
Reputation: Sky Diploma is a splendid one to behold Sky Diploma is a splendid one to behold Sky Diploma is a splendid one to behold Sky Diploma is a splendid one to behold Sky Diploma is a splendid one to behold Sky Diploma is a splendid one to behold 
Solved Threads: 100
Sky Diploma's Avatar
Sky Diploma Sky Diploma is offline Offline
Practically a Master Poster

Re: any articles or books about pointer?

 
0
  #4
Oct 19th, 2008
http://www.eternallyconfuzzled.com/t..._pointers.aspx

Here is another llink that would help.
1. Please Mark Your Thread as Solved After Getting Your Answers.
2. Please Use CODE TAGS .
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 18
Reputation: panpanf is an unknown quantity at this point 
Solved Threads: 0
panpanf's Avatar
panpanf panpanf is offline Offline
Newbie Poster

Re: any articles or books about pointer?

 
0
  #5
Oct 20th, 2008
when we use int *p=new int; we know p point to int. But i just wanna know how the compiler know p's type? When we delete a pointer to a array, how the compiler know how many bytes to release?
I am from China. I love computer science!
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 206
Reputation: grumpier has a spectacular aura about grumpier has a spectacular aura about 
Solved Threads: 31
grumpier grumpier is offline Offline
Posting Whiz in Training

Re: any articles or books about pointer?

 
0
  #6
Oct 20th, 2008
Originally Posted by panpanf View Post
when we use int *p=new int; we know p point to int. But i just wanna know how the compiler know p's type?
Because you've told it so. int *p tells the compiler that p is a pointer to int. The compiler also knows that the expression "new int" yields a value of type pointer to int, that can stored in the pointer p.

If you want a self-respecting compiler to complain bitterly, tell it "int *p = new double;" : it recognises that "new double" does not yield a pointer to int, and complains about a mismatch of types.
Originally Posted by panpanf View Post
When we delete a pointer to a array, how the compiler know how many bytes to release?
The compiler doesn't. All the compiler knows is that it's asked to delete an array (as in "delete [] whatever;") because the [] tells it that.

When dynamically allocating an array, you specifically tell it how many elements to allocate. There is nothing stopping code that manages memory allocation from keeping track of things, and retrieving the value when working with the delete operator. The methods of doing that, however, vary between compilers. And there is no portable way for your code to retrieve that value (unless you also keep track of such things yourself).
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 206
Reputation: grumpier has a spectacular aura about grumpier has a spectacular aura about 
Solved Threads: 31
grumpier grumpier is offline Offline
Posting Whiz in Training

Re: any articles or books about pointer?

 
0
  #7
Oct 20th, 2008
Oh; another tutorial on pointers is here.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC