Machine-translated by Google. Questions are authored in English.
Top

Discussion

What is the output of this code having void return-type function?

void foo()
    {
        return 1;
    }

    void main()
    {
        int x = 0;
        x = foo();
        printf("%d", x);
     }

 

  • A.1
  • B.Runtime error
  • C.Compile time error

Answer: C

Correct answer: Compile time error

A void function must not return a value, so return 1; is an error - and assigning the result of a void function to an int is a second one. Either alone would stop the program compiling.

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

Post your comment

Please log in or register to post a comment.