C Programming - Functions - Discussion

Discussion Forum : Functions - Find Output of Program (Q.No. 9)
9.
What will be the output of the program?
#include<stdio.h>
int check (int, int);

int main()
{
    int c;
    c = check(10, 20);
    printf("c=%d\n", c);
    return 0;
}
int check(int i, int j)
{
    int *p, *q;
    p=&i;
    q=&j;
    i>=45 ? return(*p): return(*q);
}
Print 10
Print 20
Print 1
Compile error
Answer: Option
Explanation:

There is an error in this line i>=45 ? return(*p): return(*q);. We cannot use return keyword in the terenary operators.

Discussion:
19 comments Page 2 of 2.

Sherine said:   10 years ago
I am asking the same question of @Vikram.

Why the out put is 10 NOT 20 as expected?

Mohan said:   8 years ago
There is a problem of type casting b/w pointer and integer @Vikram.

Aditi said:   1 decade ago
What kind of values return can return, please explain me detail?

Priyabrat said:   1 decade ago
If we use,
return i>=45 ? (*p): (*q);
den O/p will be 20.

Sonit said:   3 years ago
In ternary, we use only statements not the operations.

Muthu said:   8 years ago
We can use only one return key in ternary operator.
(1)

Nakul said:   5 years ago
A function can have only one return keyword.

Manishsoni said:   1 decade ago
Wikiok is right, it works properly.

Shubhm said:   1 decade ago
Wikiok is rite.


Post your comments here:

Your comments will be displayed after verification.