English, asked by devisunitaudaymahto, 4 months ago

Q. 4 of 10
What will be the output of the following C code having void return-type function?
#include
void fool
1
return l;
}
void main()
{
int x = 0;
X =
= foo();
40819
printf("%d", x);
CLEAR
MARK FOR REVIEW
H​

Answers

Answered by amikkr
0

Error. The code will not compile.

In C programming language, you need to define the return type of the function in the function declaration to tell the computer what datatype the function will return as output.

In the given question the function foo is a void return-type function. A void return type function means that the function will not return anything and should not have a return statement inside it.

However, the foo function is returning l in this case which is not allowed and hence it will throw out an error when the program is executed.

Moreover, while the rest of the code should work, it is not recommended to declare the main function with a void return type.

The corrected code for this problem would look something like this:

#include <stdio.h>

void foo()

{

 // No return statement is needed

}

int main()

{

 int x = 0;

 // Call the foo function and store the value in x

 x = foo();

 printf("%d", x);

 return 0;

}

#SPJ1

Answered by Jaswindar9199
0

The output of the following C code having a void return-type function will be Error. The code will not compile.

  • In C programming language, one demands to interpret the return type of the function in the function statement to instruct the computer about what datatype the function will return as output.
  • In the provided question the function is a void return-type function. A void return type function implies that the function will not be returning something and should not have a return declaration with it.
  • Still, the given function is returning in this case which is not entitled and thus it will cast off an error when the program is implemented.
  • Also, while the remainder of the code should operate, it is not approved to proclaim the major function with a void return category.

#SPJ1

Similar questions