C Programming - Control Instructions - Discussion

Discussion Forum : Control Instructions - Find Output of Program (Q.No. 11)
11.
What will be the output of the program?
#include<stdio.h>
int main()
{
    int k, num = 30;
    k = (num < 10) ? 100 : 200;
    printf("%d\n", num);
    return 0;
}
200
30
100
500
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
39 comments Page 2 of 4.

Sushant shankar mahadik said:   1 decade ago
k = (num<10) ?100:200 is become false &.

Here print k so answer will be 30.

Sarath Chandra said:   1 decade ago
k = (num < 10) ? 100 : 200;

Becomes false, since num=30 which is greater than 10.

So k=200. But its has nothing to do with value of num and remains same.

Therefore num = 30 itself.

Visva said:   1 decade ago
Num value is declared as 30, in 2nd line they specified k not about m. So finally the num value printed as 30.

Veerappa sudhakaran said:   1 decade ago
Exactly num value = 30.

Radhanath said:   1 decade ago
Absolutely to print the value of num=30.

Rathan said:   1 decade ago
In this program:

int main()
{
int k, num = 30;
k = (num < 10) ? 100 : 200;
printf("%d\n", num);
return 0;
}

Here 30<10 condition is false.
k=200 but in printf function asked the value of 'num'.

So output is 30.
(1)

Jignesh patel said:   1 decade ago
In this programme conditional operators process does not assign value to number so output of num remains same as it is so num=30 only assignment operator can change value of number variable.

Rohan Dutta said:   1 decade ago
Here the question is about the value of "num", not "k". When we are using the condition the value of "k" has been changed. But the value of "num' remains unchanged. Therefore the output is num=30.

Reddy'Siva said:   1 decade ago
Here the question is about the value of the variable "num" and not "k" that's why the answer is 30 good thing.

Manoj said:   1 decade ago
#include<stdio.h>
int main()
{
int k, num = 30;
k = (num < 10) ? 100 : 200;
printf("%d\n", num);
return 0;
}

Here in this program,

k = (num <10)?100:200;

The condition is false so the result is 200 but thus in the next statement printf("%d\n", num); we print the value of num so the result is 30. what is assigned it previously?


Post your comments here:

Your comments will be displayed after verification.