Monday, 26 February 2018

C interview question 6

What will be the output of the given code?

void main()
{
int i=1;
i=!i>2;
printf ("i=%d",i);
}
Ans: 0


Reason:
!1 will be 0 [Because of precedence of operator, ! Operator has more precedence than the > operator]
0 is compared with 2
Condition  greater than fails
So the value of i will be 0

No comments:

Post a Comment

C interview question 8

What will be the output of the given code? #include <stdio.h> int main(void) { float a = 3.14; printf("%f",a%3); ...