What is the output of the following code? #include <iostream> using namespace…
2021
What is the output of the following code?
#include <iostream>
using namespace std;
int main()
{
int a = 3, b, *p, **q;
p = &a;
q = &p;
b = 2 * (**q + *p);
cout << b;
}Answer: B. 12 — Step-by-step execution: a = 3 p = &a p stores the address of a. q = &p q stores the address of p. *p gives the value of a → 3 *q gives the value stored in p →…
- A.
3
- B.
12
- C.
18
- D.
24
Attempted by 184 students.
Show answer & explanation
Correct answer: B
Step-by-step execution:
a = 3p = &apstores the address ofa.q = &pqstores the address ofp.*pgives the value ofa→3*qgives the value stored inp→ address ofa**qgives the value ofa→3
Conceptually, the intention is:
*p = 3**q = 3
So:
b = 2 * (**q + *p)
= 2 * (3 + 3)
= 2 * 6
= 12Hence, the output is 12.
Loading lesson…