Pointer Values

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

Join Date: Mar 2008
Posts: 31
Reputation: kinger29 is an unknown quantity at this point 
Solved Threads: 1
kinger29 kinger29 is offline Offline
Light Poster

Pointer Values

 
0
  #1
Jul 29th, 2008
I was reviewing some material over pointers in a book called C++ Primer 4th Edition and it said there were four possible values that you can set to a pointer.
  1. A constant expression with a value of 0
  2. An address of an object of an appropriate type
  3. The address one past the end of another object
  4. Another valid pointer of the same type

I am not sure exactly what is meant by the third type. Is past a typo that should be passed?

From what I understand this is what is meant by the other three types
1)
const int c_ival = 0;
int *pNum1 = c_ival;

2)
int ival = 1;
int *pNum2 = &ival;

3)
????

4)
int *pNum3 = pNum2;

Any help would be appreciated thanks.
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 401
Reputation: CoolGamer48 is on a distinguished road 
Solved Threads: 40
CoolGamer48's Avatar
CoolGamer48 CoolGamer48 is offline Offline
Posting Pro in Training

Re: Pointer Values

 
0
  #2
Jul 29th, 2008
I think what he's referring to in #1 is a NULL pointer:
  1. int* x = NULL;
  2. //or
  3. int* x = 0;

I'm guessing this is what is meant by #3:
  1. int x[10] = {0};
  2. x[3] = 5;
  3. x[4] = 13;
  4. int* pInt = (&x[3])+1;

*pInt would be 13
I'm a student. If my statements seem too absolute, feel free to coat them with "In my opinion..." or "I believe...".
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 749
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: Pointer Values

 
0
  #3
Jul 29th, 2008
Case 3 means you can do this.
  1. int arr[10];
  2. int *pStart = arr;
  3. int *pEnd = &arr[10]; // one past the end
  4. while ( pStart < pEnd ) {
  5. pStart++;
  6. }
Note that whilst you can POINT to the element just off the end of the array, any attempt to dereference pEnd would be undefined behaviour.
Reply With Quote Quick reply to this message  
Reply

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


Thread Tools Search this Thread



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

©2003 - 2009 DaniWeb® LLC