0
Pointer reference and derefrence
Confuse about pointer reference & derefrence, its value assignment, its calling and pointing then. *ptr = new int ; *ptr=5; Confuse about this!!! Kindly summaries this concept.
2 Respuestas
+ 1
~ swim ~ thanks, I fixed it.
0
pointer reference points to a memory address.
dereference returns the value at that memory address.
ex:
int * ptr;
int x;
ptr = &x ; // pointing to the memory address of x.
*ptr = 5; //it assigns 5 to x
now if you want to print the value of x, you could just print x directly or you could dereference the pointer and the results would be the same.
if you don't dereference the pointer it would print the memory address.
cout << x ; // prints 5
cout << *ptr ; //prints 5
cout << ptr ; // prints memory address of x
you dereference a pointer with *