Knowee
Questions
Features
Study Tools

What will be the output of the following C code? #include <stdio.h> int main() { int i = 10; void *p = &i; printf("%f\n", *(float*)p); return 0; }

Question

What will be the output of the following C code? #include <stdio.h> int main() { int i = 10; void *p = &i; printf("%f\n", (float)p); return 0; }

🧐 Not the exact question you are looking for?Go ask a question

Solution

The output of the given C code is undefined. This is because you are trying to dereference a void pointer p as a float pointer, but p actually points to an integer. The behavior of this code is not defined in the C standard, so it may produce different results on different systems or compilers. It's likely to either crash or print some random number.

Similar Questions

what will be the output of the c program?

What will be the output of the following code?

What will be the output of the following C++ code?

What will be the output of the following program?

What will be the output of the following C code?#include <stdio.h>int main() {    int i;    for (i = 0; i < 5; i++);    printf("%d\n", i);    return 0;}

1/4

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.