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;
}
Discussion:
39 comments Page 2 of 4.
Radhanath said:
1 decade ago
Absolutely to print the value of num=30.
Veerappa sudhakaran said:
1 decade ago
Exactly num value = 30.
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.
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.
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.
Sushant shankar mahadik said:
1 decade ago
k = (num<10) ?100:200 is become false &.
Here print k so answer will be 30.
Here print k so answer will be 30.
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?
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?
Yoga said:
9 years ago
Please explain me the answer.
Ravi said:
9 years ago
@Meenu.
You explained clearly I clarify my doubt with the help of your explanation, Thanks.
You explained clearly I clarify my doubt with the help of your explanation, Thanks.
Prathamesh said:
8 years ago
Thanks for all the given explanation.
Kummi said:
6 months ago
Yes, 30 is right. I too agree.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers