Home » C Programming » Pointers » Question
  1. What will be the output of the following C code?
    #include <stdio.h>
    int *fun();
    int main()
    {
    int *ptr = fun();
    printf("%d\n", *ptr);
    }
    int *fun()
    {
    int *p = (int*)malloc(sizeof(int));
    *p = 11;
    return p;
    }
    1. Compilation Error
    2. 11
    3. Undefined behaviour
    4. Segmentation fault/runtime crash since pointer to local variable is returned
    5. None of these
Correct Option: B

11



Your comments will be displayed only after manual approval.