C Programming - Input / Output - Discussion

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;
}

[A]. k == 1 is TRUE
[B]. 1 == 1 is TRUE
[C]. 1 == 1 is FALSE
[D]. K == 1 is FALSE

Answer: Option B

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


Kumar said: (Mar 11, 2014)  
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.

MacĂ­K said: (Nov 6, 2015)  
There will be no space between is and TRUE.

Result should be: 1 == 1 is TRUE.

Post your comments here:

Name *:

Email   : (optional)

» Your comments will be displayed only after manual approval.