Multiple choice technology programming languages

What will be the output of the following program : void main() { int val=50; void ptr; ptr=&val; printf("%d %d",val,(int *)ptr); }C

  1. Compile-Time Error

  2. 50 50

  3. 50 0

  4. None of the above

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

A void pointer can hold the address of any data type. When we assign &val to ptr, then cast ptr back to (int*) before dereferencing, we correctly retrieve the original value 50. The program prints the value twice - once directly from val, once through the pointer.