0

Can someone please explain this code? I'm having confusion with the output ?

#include <iostream> using namespace std; int main() { int score = 4; cout << &score << endl; return 0; } output: 0×28ff1c

6th Dec 2016, 3:52 PM
neil
neil - avatar
5 Answers
+ 2
"&" operator is used to access the address of a variable. That number you see is just the location where the variable is stored in memory.
6th Dec 2016, 3:55 PM
Nikunj Arora
Nikunj Arora - avatar
+ 1
& operator is used when working with pointers and when passing arguments to a function by reference. eg- int a = 5; int *p = &a; // now p is pointing to a
6th Dec 2016, 4:20 PM
Nikunj Arora
Nikunj Arora - avatar
+ 1
& is called the address operator. Int number=3; Cout<<&number; Would print out a random number with letters. This is because you printed the address where number is stored in stack. Like mention before by others the address operator & is used when working with pointers to point at a specifically location.
7th Dec 2016, 8:16 PM
Leonardo Roman
Leonardo Roman - avatar
0
remove the '&' sign.
6th Dec 2016, 3:54 PM
Akash Middinti
0
what's the point in learning & operator if we remove it?
6th Dec 2016, 4:07 PM
neil
neil - avatar