What will be the output of the following C code?#include <stdio.h>int *m(){int *p = 5;return p;}void main(){int *k = m();printf("%d", k);}5Junk value0Error
Question
What will be the output of the following C code?#include <stdio.h>int *m(){int *p = 5;return p;}void main(){int *k = m();printf("%d", k);}5Junk value0Error
Solution 1
The output of the given C code will be an Error.
The reason is that in the function m(), you are trying to assign an integer value to a pointer variable p. In C, a pointer should be assigned an address of a variable, not a direct value.
So, when you try to compile this code, it will throw a compilation error saying something like "assignment makes pointer from integer without a cast".
Solution 2
The output of the given C code will be an Error.
The reason is that in the function m(), you are trying to assign an integer value to a pointer variable p. In C, a pointer should be assigned the address of a variable, not a direct value.
So, when you try to compile this code, it will throw a compilation error saying something like "assignment makes pointer from integer without a cast".
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;}
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.