Home » C Programming » Functions » Question
  1. What will be the output of the following C code having void return-type function?
    #include <stdio.h>
    void fun()
    {
    return 5;
    }
    void main()
    {
    int n = 4;
    n = fun();
    printf("%d", n);
    }
    1. 5
    2. 4
    3. Compilation Error
    4. Runtime Error
    5. None of these
Correct Option: C

Compilation Error

main.c: In function ‘fun’:
main.c:4:16: warning: ‘return’ with a value, in function returning void
return 5;
^
main.c:2:10: note: declared here
void fun()
^~~
main.c: In function ‘main’:
main.c:9:11: error: void value not ignored as it ought to be
n = fun();



Your comments will be displayed only after manual approval.