341 views
1 votes
1 votes
#include<stdio.h>
int fun(int a)
{
 a > 20 ? printf("10"): printf("20");
}
int main()
{
int b=fun(21);
return 0;
}

 

This program gives output but below program not gives output

 

#include<stdio.h>
int fun(int a)
{
 a > 20 ? return 10: return 20;
}
int main()
{
int b=fun(21);
printf("%d",b);
return 0;
}

1 Answer

0 votes
0 votes
return doesn't work for ternary operator.

Try

if(a>20) return 10; else return 20;

No related questions found