What will be the output of the following C++ code?
int x = 25;
int *p = &x;
cout << *p;
Options
-
A.
25
-
B.
Address of x
-
C.
Garbage value
-
D.
More than one of the above
-
E.
None of the above
Correct Answer (Detailed Explanation is Below)
A.
25
Detailed Explanation
Answer: (A) 25
The expression &x obtains the address of variable x and stores it in pointer p.
The dereference operator *p accesses the value stored at the address held by p.
Since x = 25, dereferencing p gives 25.
Therefore, the output is 25.