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.

I think what he's referring to in #1 is a NULL pointer:

int* x = NULL;
//or
int* x = 0;

I'm guessing this is what is meant by #3:

int x[10] = {0};
x[3] = 5;
x[4] = 13;
int* pInt = (&x[3])+1;

*pInt would be 13

Case 3 means you can do this.

int arr[10];
int *pStart = arr;
int *pEnd = &arr[10];  // one past the end
while ( pStart < pEnd ) {
  pStart++;
}

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.