Home » C Programming » Functions » Question
  1. What will be the output of the following C code?
    #include <stdio.h>
    int *fun();
    void main()
    {
    int *ptr = fun();
    printf("Welcome ");
    printf("%d", ptr[0]);
    }
    int *fun()
    {
    int n[5] = {15, 18, 10};
    return n;
    }
    1. Compilation Error
    2. Welcome
    3. 15 18 10
    4. Segmentation fault
    5. None of these
Correct Option: D

Segmentation fault

main.c: In function ‘fun’:
main.c:12:16: warning: function returns address of local variable [-Wreturn-local-addr]
return n;
^
$main
timeout: the monitored command dumped core
sh: line 1: 179205 Segmentation fault timeout 10s main



Your comments will be displayed only after manual approval.