Pages

Friday, July 12, 2024

Interview Question :Find the output of the following C program



#include <stdio.h>

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



Solution : 
                 1 == 1 is TRUE

Explanation : 

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

The underlined statement can be expanded as:

                        if(k == 1)
                        {
                                "TRUE"
                        }
                        else 
                        {
                                "FALSE"
                        }
                        
 Since k is initialised to 1,Hence
                            k = TRUE
The datatype assigned for k is integer and its value is 1

So %d in the printf statement will print 1 
While the %s will print the string "TRUE"

No comments:

Post a Comment

What is anti- Debugging

  Anti- debugging is how we can stop somebody from debugging our system and getting all the information out of your subsystem.