Question:medium

What will be the output of the following code? verbatim #include <iostream> using namespace std; int main() int a = 10; int ptr = &a; cout << ptr; return 0; verbatim

Show Hint

Remember the two fundamental pointer operators:&` (address-of) gives you the address of a variable, and` (dereference) gives you the value at a given address.
Updated On: Jul 2, 2026
  • Address of a
  • 10
  • 0
  • Compilation error
Show Solution

The Correct Option is B

Solution and Explanation

Step 1: Set up the memory picture first.
The line int a = 10 creates a variable a holding the value 10 somewhere in memory, and the pointer is then made to store the address of that memory location, not the value itself.
Step 2: Distinguish the pointer from what it points to.
Printing the pointer on its own would show a memory address, but dereferencing it tells the compiler to go to the address stored in the pointer and fetch the value sitting there.
Step 3: Apply dereferencing to get the printed value.
Since the pointer points at a, dereferencing it retrieves exactly the value stored in a, which is 10, and that is the value that ends up printed to the console.
\[ \boxed{10} \]
Was this answer helpful?
0