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);
}
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.
Please log in or register to report this question.