10?"Ps\n":"%s\n", str);  return 0; }"/>
Home / C Programming / Control Instructions :: Discussion

Discussion :: Control Instructions

  1. What will be the output of the program?

     #include
     int main()
     {     
         char str[]="C-program";  
         int a = 5;  
         printf(a >10?"Ps\n":"%s\n", str);     
         return 0;
     } 
    

  2. A.

    C-program

    B.

    Ps

    C.

    Error

    D.

    None of above

    View Answer

    Workspace

    Answer : Option A

    Explanation :

    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".


Be The First To Comment