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.

23rd Apr 2019, 7:13 AM
Tahir Amin
Tahir Amin - avatar
3 ответов
+ 1
~ swim ~ thanks, I fixed it.
23rd Apr 2019, 9:30 AM
Bahhaⵣ
Bahhaⵣ - avatar
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 *
23rd Apr 2019, 7:31 AM
Bahhaⵣ
Bahhaⵣ - avatar