What will be the output of the following C code? [code] #include <stdio.h> int *f(); int main() { int *p = f();

Khánh Đoan

New member
What will be the output of the following C code?
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;
    }
A. 10
B. Compile time error
C. Segmentation fault/runtime crash since pointer to local variable is returned
D. Undefined behaviour
 

Tìm kiếm

Back
Top