Top

Discussion

What is the output of this C code?

#include 
    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

Answer: A

No answer description available for this question.

No comment is present. Be the first to comment.
Loading…

Post your comment