Answer to Question #53570 in C for rajashree g.s.

Question #53570
#include<stdio.h>
int main()
{
int x=15;
printf("\n %d %d %d",x!=15,x=20,x<30);
return 0;
}

In this program x is already assigned the value 15. what will be the output and explain sir.
1
Expert's answer
2015-07-22T01:28:27-0400
Answer:

Note: The program won’t compile if “#include” statement is not followed by included library <stdio.h>
“printf” function outputs text in quotes which is the first argument and next arguments in place of specificators which starts with percent ‘%’ symbol in text. ‘\n’ is an escape sequence for new line, and ‘%d’ is specificator of decimal integer. Therefore, what will be outputted is new line, then space, integer, space, integer, space and an integer.
The first integer is x!=15, which is actually a Boolean value received from comparing x and 15. Since x equals 15 and != stands for “not equal” the comparing results in false. When false Boolean value is casted into integer it becomes zero, thus, the first integer is 0.
The second integer is x=20, which is a result of assigning x to 20. The result of assigning is the assigned value itself, thus, the second integer is 20.
The third integer is x<30, which is actually a Boolean value received from comparing x and 20. Since x equals 20 (not 15, because of the assignment in previous argument) and < stands for “less than” the comparing results in true. When true Boolean value is casted into integer it becomes one, thus, the first integer is 1.
Thus, the program outputs new line, space, 0, space, 20, space, 1.

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS