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 1 of 4.

Kummi said:   5 months ago
Yes, 30 is right. I too agree.

Varsha said:   5 years ago
If (30<10) 200 is executed. If that statement true means 100 is executed. So the answer is 200.
(1)

Chetan said:   7 years ago
Because here condition is true but num variable store in 30 value is not changed. So answer print is num value.
(5)

Prathamesh said:   8 years ago
Thanks for all the given explanation.

Kundana said:   8 years ago
1) int num=1; / initialized 'num' variable/.
2)k= (num<10) ? 100 : 200; // k= (30<10) if statement true then print. ("100") if statement is false then print ("200") //
3) But in program, they asked to print 'num' which is already initialized (int num = 30) so will be printed.
(3)

Saloni kamboj said:   9 years ago
k = (num < 10) ? 100 : 200;

I am not getting this statement, Please explain it to me.
(2)

Ravi said:   9 years ago
@Meenu.

You explained clearly I clarify my doubt with the help of your explanation, Thanks.

Yoga said:   9 years ago
Please explain me the answer.

Sandy said:   9 years ago
Step 1: int k, num=30; // Here variable num is initialized to '30',
Variable k is declared, but not initialized.

Step 2: k = (num < 10) ? 100 : 200; // Is nothing but if(30 < 10) k = 100; else k=200;
Hence this condition will be failed. And k value becomes 200 (k = 200).

Step 3: printf("%d\n", num); // Here it is printing num value but not asked about to print k value.

So, finally will get output 30.
(1)

P.kranthi kumar said:   9 years ago
k = (num<10)?100:200 is become false&

Here print the k, so the answer will become 30.


Post your comments here:

Your comments will be displayed after verification.