C Programming - Input / Output - Discussion

Discussion Forum : Input / Output - Find Output of Program (Q.No. 2)
2.
What will be the output of the program ?
#include<stdio.h>

int main()
{
    int k=1;
    printf("%d == 1 is" "%s\n", k, k==1?"TRUE":"FALSE");
    return 0;
}
k == 1 is TRUE
1 == 1 is TRUE
1 == 1 is FALSE
K == 1 is FALSE
Answer: Option
Explanation:

Step 1: int k=1; The variable k is declared as an integer type and initialized to '1'.

Step 2: printf("%d == 1 is" "%s\n", k, k==1?"TRUE":"FALSE"); becomes

=> k==1?"TRUE":"FALSE"

=> 1==1?"TRUE":"FALSE"

=> "TRUE"

Therefore the output of the program is 1 == 1 is TRUE

Discussion:
3 comments Page 1 of 1.

Nikhil Narendra patil said:   1 year ago
Yes, agree the answer is right.

Macík said:   8 years ago
There will be no space between is and TRUE.

Result should be: 1 == 1 is TRUE.

Kumar said:   10 years ago
How can it print "1" in the place of k because in printf there is %s? In my thought it need to show compile error.

Post your comments here:

Your comments will be displayed after verification.