+ 2
What will be the output of the following C code?
#include <stdio.h> int *f(); int main() { int *p = f(); printf("%d\n", *p); } int *f() { int *j = (int*)malloc(sizeof(int)); *j = 10; return j; }
4 Respuestas
0
Sorry to say but there will not be any output as I found there is some error in your code. Just check your code again
0
All you have to do is just reading error reason:
As you can see it says malloc is declared in stdlib library and you fogot to include it
0
Just add "#include <stdlib.h>" without quotes below "#include <stdio.h>".
This is required to declare the prototype of malloc().
Now the output of the program will be 10: the content of the memory that you allocated and initialized inside the function f() 🤷
0