Pick the best statement for the following program snippet:
(A) It will print “var=5 and *ptr=2000”
(B) It will print “var=5 and *ptr=5”
(C) It will print “var=5 and *ptr=XYZ” where XYZ is some random address
(D) Compile error
Explanation: Key point in the above snippet is dereferencing of void pointer. It should be noted that dereferencing of void pointer isn’t allowed because void is an incomplete data type. The correct way to assign value of 5 would be first to typecast void pointer and then use it. So instead of *ptr, one should use *(int *)ptr. Correct answer is d.
Quiz of this Question