| | |
Pointer Values
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Mar 2008
Posts: 31
Reputation:
Solved Threads: 1
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.
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.
- A constant expression with a value of 0
- An address of an object of an appropriate type
- The address one past the end of another object
- 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:
I'm guessing this is what is meant by #3:
*pInt would be 13
C++ Syntax (Toggle Plain Text)
int* x = NULL; //or int* x = 0;
I'm guessing this is what is meant by #3:
C++ Syntax (Toggle Plain Text)
int x[10] = {0}; x[3] = 5; x[4] = 13; 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...".
Case 3 means you can do this.
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.
C++ Syntax (Toggle Plain Text)
int arr[10]; int *pStart = arr; int *pEnd = &arr[10]; // one past the end while ( pStart < pEnd ) { pStart++; }
![]() |
Similar Threads
- 32-bit Pointer in C (C)
- Deleting a pointer? (C++)
- structures containing a pointer to an array (C++)
- C pointer problem (C)
- getting strange values in display??? (C++)
- help with sort using Calendar class getting null pointer exception (Java)
- The improtance of replacing values in pointers (C)
- *Pointer program problem. (C++)
Other Threads in the C++ Forum
- Previous Thread: Reading bytes from a particular address
- Next Thread: Bool problem
| Thread Tools | Search this Thread |
api array arrays based binary c++ c/c++ calculator char char* class classes code coding compile console conversion count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






