C - Operators - Discussion

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

 



Q.

What will be output when you will execute following c code?

#include
int main(){
char a=250;
int expr;
expr= a+ !a + ~a + ++a;
printf("%d",expr);
return 0;
}

A. 249 B. 250
C. 0 D. -6

Answer: Option D
Explaination:

 


205 is beyond the range of signed char. Its corresponding cyclic value is: 6 So, a = -6

Operator! , ~ and ++ have equal precedence. And it associative is right to left.
So, First ++ operator will perform the operation. So value a will -5
Now, Expr = -5 + !-5 + ~-5 + -5
= -5 + !-5 + 4 - 5
= -5 + 0 + 4 - 5
= -6



Discussion

Your Comments Goes here...
NameDiscussion