C - Operators - Discussion

You Are Here :: Home > C > Operators - Discussion

 



Q.

What will be output if you will compile and execute the following c code?

#include
int main(){
int i=3;
if(3==i)
printf("%d",i<<2<<1);
else
printf("Not equal");
}

A. 1 B. 24
C. 48 D. Not equal

Answer: Option B
Explaination:

 


Associative of bitwise left shifting operator is left to right. In the following expression:

i<<2<<1 There are two bitwise operators. From rule of associative leftmost operator will execute first.
i <<><<> After execution of leftmost bitwise left shifting operator: so i=i*pow(2,2)
=3*
.



Discussion

Your Comments Goes here...
NameDiscussion