Control Instructions

Q1:
What will be the output of the program?
#include<stdio.h>
int main()
{
    char str[]='C-program';
    int a = 5;
    printf(a >10?'Ps\n':'%s\n', str);
    return 0;
}

A C-program

B Ps

C Error

D None of above

ANS:A - C-program

Step 1: char str[]='C-program'; here variable str contains 'C-program'.
Step 2: int a = 5; here variable a contains '5'.
Step 3: printf(a >10?'Ps\n':'%s\n', str); this statement can be written as

if(a > 10)
{
    printf('Ps\n');
}
else
{
    printf('%s\n', str);
}
Here we are checking a > 10 means 5 > 10. Hence this condition will be failed. So it prints variable str. Hence the output is 'C-program'.



img not found
img

For help Students Orientation
Mcqs Questions

One stop destination for examination, preparation, recruitment, and more. Specially designed online test to solve all your preparation worries. Go wherever you want to and practice whenever you want, using the online test platform.