C - Functions - Discussion

You Are Here :: Home > C > Functions - Discussion

 



Q.

Point out the error, if any in the following program.

main()
{
int b;
b=f(20);
printf("%d",b);
}
int f(int a)
{
a>20 ? return(10) : return(20);
}

A. return(a ? 10 : 20) B. return(20 ? 10 : 20)
C. return(a>20 ? 10 : 20) D. return(a>20 , 10 : 20)

Answer: Option D
Explaination:

Return statement cannot be used as shown with the conditional operators. Instead the following statementmay be used. return(a>20 ? 10 : 20).



Discussion

Your Comments Goes here...
NameDiscussion