Multiple choice technology programming languages

main() { int i=20, *k; k=&i; printf("\n%d %d", i, k); ++*k; printf("\n%d %d", i, k); (*k)++; printf("\n%d %d", i, k); } Let the output of first print statement is 20 1000. What is the output of 2nd and third print statements ?

  1. 21 1000 21 1002

  2. 21 1000 Garbage_value 1002

  3. 21 1000 22 1002

  4. 21 1000 22 1000

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

The statement ++*k increments the value stored at address k (variable i) to 21, leaving the address unchanged at 1000. Next, (*k)++ increments the value of i again to 22 while keeping k pointing to address 1000. Other options incorrectly modify the pointer address.