Monday, March 31, 2008
Sunday, March 2, 2008
char char_A = 'A';
const char * myPtr = &char_A;
*myPtr = 'J'; // error - can't change value of *myPtr
2. Constant Pointerchar char_A = 'A';
char char_B = 'B';
char * const myPtr = &char_A;
myPtr = &char_B; // error - can't change address of myPtr
Difference between Reference and Pointer in C++
- Reference should be initialized and pointer need not be.
- Reference can’t point to NULL and pointer can.
- Reference can’t be changed to some other objects it is once initialized but pointer can be.
- Pointer can be incremented or decremented and subjected to any pointer arithmetic operations, but reference can’t.