-6

I'm confused about these logical operators. can someone please explain the precedence and associative rules of these operators. in bit wise operations, a=011, b=010 and c=001 in d whether a should be negated first or should the evaluation be started from right to left and whose precedence is higher? the output is 4, 3,3.

#include<stdio.h>
int main()
{
 int a=3,b=2,c=1,d,e,f;
 d=~a|b&c;
 printf("d=%d\n",d);
 e=a|b&~c;
 printf("d=%d\n",e);
 f=a|b&c;
 printf("d=%d\n",f);
 return 0;
}

1 Answers1

2

C unary operators (e.g., ~) have higher precedence than binary operators.

& operator has higher precedence than | operator.

See man 7 operators for a summary of operator precedence.

ouah
  • 142,963
  • 15
  • 272
  • 331