Examveda
Examveda

Determine output of the following program code.
#include<stdio.h>
void main()
{
   int a, b=7;
   a = b<4 ? b<<1 : ++b>4 ? 7>>1 : a;
   printf("%d %d", a, b);
}

A. 3 7

B. 7 3

C. 8 3

D. 3 8

E. None of these

Answer: Option D


This Question Belongs to C Program >> Operators And Expressions

Join The Discussion

Comments ( 6 )

  1. Test Mail
    Test Mail :
    1 year ago

    int a,b=7;
    if(b1;
    else
    a=a;
    }

  2. Sudheer Sudheer
    Sudheer Sudheer :
    4 years ago

    The Answer is a=3 and b=7.
    Given Expression a = b1 : a;
    We can write this in this format....

    if ( b>1; // Do Right Shift Operation
    } 7 = 0000 0111 need to add a bit ' 0 ' in the LeftMost.....
    else Then 0000 0011 = 3 i.e a = 3.
    {
    a=a;
    }
    }

  3. Ajinkya Londhe
    Ajinkya Londhe :
    7 years ago

    33

  4. Vishwajeet Fartade
    Vishwajeet Fartade :
    7 years ago

    ok

  5. Ramachandran Pillai
    Ramachandran Pillai :
    8 years ago

    The answer is :
    7 false
    So, executes ++b>4 ? 7>>1 : a
    ie; 8>4 ? True .
    So, a=7>>1
    ie;
    0111 is shifted right by one time
    => 0011 ie a=3
    Thus, b=8 and a=3

  6. Rohit Raina
    Rohit Raina :
    8 years ago

    how b will incremented?

Related Questions on Operators and Expressions