int score = 5; int *scorePtr; scorePtr = &score; cout << scorePtr << endl; //Outputs "0x29fee8" | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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

11th Jun 2018, 7:30 AM
rohit
3 Answers
+ 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;
11th Jun 2018, 7:40 AM
Kinshuk Vasisht
Kinshuk Vasisht - avatar
+ 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 )
11th Jun 2018, 7:44 AM
Aveek Bhattacharyya
Aveek Bhattacharyya - avatar
0
use court<<*scorePtr<<endl; to get the value stored in pointer
22nd Jun 2018, 2:27 PM
Ashwini Kumar
Ashwini Kumar - avatar