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.

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.

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.

Prasad said:   1 decade ago
Here num=30 is assigned the value when you compare proparly 30<10 it false No than he willbe stop and they cannot exicuted the next statment and than 30 will be print.

Sudhakar said:   1 decade ago
In printf statement dey asked what is outpt of num. Not k. Here is explanation.

Here we want only output for num. So num=30.

If we want output of k then it is 200.

Rakesh said:   1 decade ago
Actually we don't have any use of K there, because it is asking for num value in print out statement.

Its a type of question to know the concentration of a user.

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)

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.

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.

Sunny said:   1 decade ago
In the program we are printing the value of num. We are not printing the value of k. So the output is 30.

Parhiban said:   1 decade ago
Does not use ternary operator. Because simply say that declare vale 30. Just print out the declare value.


Post your comments here:

Your comments will be displayed after verification.