To answer this question, let's go through the given program step by step:
- The program starts by declaring a variable
val and initializing it with the value 5.
- Then, a void pointer
ptr is declared.
- The next line
*(int *)ptr=5; tries to assign the value 5 to the memory location pointed by ptr. However, since ptr is not pointing to any valid memory location, this line will result in undefined behavior. This is because ptr is uninitialized and pointing to an unknown memory location.
- Next, the line
val=ptr; tries to assign the value of ptr to val. Since ptr is uninitialized, this will also result in undefined behavior.
- Finally, the line
printf("%d %d",*(int *)val,*(int *)ptr); tries to print the values at the memory locations pointed by val and ptr. However, since both val and ptr are uninitialized and not pointing to valid memory locations, this will also result in undefined behavior.
Therefore, the correct answer is option A) Compile-Time Error.