Can nay one tell me what is the difference between (pointer and reference ) the entries below:
thank youCode:int n3 = new int (13); and int * & n3 = new int (13);
Can nay one tell me what is the difference between (pointer and reference ) the entries below:
thank youCode:int n3 = new int (13); and int * & n3 = new int (13);
A reference can be thought of as a special type of pointer with certain restrictions. references have to be initialized at the time of declaration and cannot be changed in the code later , whereas this does'nt hold true with the pointers.Pointers and Reference looks similar but there are some difference between both of them.
Pointer maynot associate with a legitimate memory but refernces should associate with certain memory.A pointer can be re-assigned any number of times while a reference can not be reassigned after initialization. Reference cannot be changed whereas pointer value can be changed. Actually, const pointer = reference.A pointer can point to NULL while reference can never point to NULL.
POINTER
REFERENCECode:int b = 11; int *P = &b; //It is not necessary Another way is : int b = 11; int *q; q = &b; You can create the array of Pointer,assign NULL to the pointer like int *q = NULL;
Code:int &b = 10; int &b; int &b = NULL; //Error You can not use reference to reference.
Bookmarks