| | |
Pointer Values
Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
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
Views: 389 | Replies: 2
| Thread Tools | Search this Thread |
Tag cloud for C++
6 api application array arrays assignment beginner binary bitmap c++ c/c++ calculator char class classes code coding compile compiler console conversion convert count data database delete developer display dll email encryption error file forms fstream function functions game generator getline givemetehcodez graph homeworkhelper iamthwee ifstream image input int java lazy lib loop looping loops map math matrix memory multidimensional multiple newbie news node number output parameter pointer problem program programming project proxy python random read recursion recursive reference return sort sorting string strings struct template templates text tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






