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 3 of 4.
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.
Its a type of question to know the concentration of a user.
Brij said:
1 decade ago
step 1: num = 30
step 2: k = 200
step 3: print the value of num i.e 30;
step 2: k = 200
step 3: print the value of num i.e 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.
Sarath K C said:
1 decade 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.
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.
Abc said:
1 decade ago
It have the value of num not of k % its 30.
So it will print 30.
So it will print 30.
Manal said:
1 decade ago
I don't understand the k=(num< 100) 100:200
Golu said:
1 decade ago
Here if condition is not satisfied so it assumes the garbage value.
Parhiban said:
1 decade ago
Does not use ternary operator. Because simply say that declare vale 30. Just print out the declare value.
Varsha said:
1 decade ago
Thanx Meenu, I was not knowing the meaning of this statement. It really helped me.
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.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers