0
int score = 5; int *scorePtr; scorePtr = &score; cout << scorePtr << endl; //Outputs "0x29fee8"
why is the output 0×29fee8 ? 0×29fee8 is not declared in program
3 ответов
+ 5
0x29fee8 is the address of the variable score. It is the location where the computer stores the variable for your access in the static memory.
A pointer stores an address as a value. When you print a pointer directly, you can see the address it points to. To see the value at the address, use the dereference operator, '*'.
Eg = cout<<*scorePtr<<endl;
+ 1
cout << *scorePtr << endl;
You have to dereference the pointer
The output is the memory address that the pointer is pointing ( address of the variable score )
0
use court<<*scorePtr<<endl; to get the value stored in pointer