Predict the output of the following Code?
2019
Predict the output of the following Code?

Answer: B. 12 12 — ptr is initialized with a, so it points to the first element of the array, a[0]. Initially, a[0] is 10. The expression *ptr += 2 is equivalent to *ptr = *ptr…
- A.
30 30
- B.
12 12
- C.
12 30
- D.
10 20
Attempted by 51 students.
Show answer & explanation
Correct answer: B
ptr is initialized with a, so it points to the first element of the array, a[0]. Initially, a[0] is 10.
The expression *ptr += 2 is equivalent to *ptr = *ptr + 2. Therefore a[0] becomes 10 + 2 = 12, and the value of this assignment expression is also 12. The first printf prints 12.
The pointer has not moved; it still points to a[0]. So the second printf also prints 12.
Hence, the output is 12 12.
Loading lesson…