Question 69

Computer Awareness Data Structure Medium

What is the output of this C code? \[\]void main() { \[\]int x = 18; \[\]void *ptr = &x; \[\]printf("%f\n", *(float *)ptr);

(A) compile time error
(B) undefined behaviour
(C) 10
(D) 0.000000\[\]
View Dynamic Solution & Explanation
Correct Solution: Option B

Step-by-step Solution:

This is because dereferencing a cast pointer from an integer to a float introduces undefined behaviour. \[\] Correct Answer: (b)