Question:

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
collegedunia
Verified By Collegedunia

The Correct Option is B

Solution and Explanation

Let's trace the code execution:
1. int a = 10;`: An integer variablea` is created and initialized with the value 10.
2. int ptr = &a;`: int ptr` declaresptr` as a pointer to an integer. &a` is the address-of operator. It gets the memory address of the variablea`. So, this line initializes the pointerptr` to hold the memory address ofa`.
3. cout << ptr;`: ptr` by itself holds the address ofa`. ptr` is the dereference operator. It accesses the value stored at the address thatptr` is pointing to. Sinceptr` points toa`,ptr` is equivalent to the value ofa`. The value ofa` is 10.
4. The program will print the value 10 to the console.
Was this answer helpful?
0
0