15.4k views
17 votes
Discuss operator precedence in C programming with examples ​

1 Answer

10 votes

Answer:

See picture for the operator precedence.

A very common pitfall is the << (shift) operator.

It has lower precedence than, for instance, the + operator, so a statement like:

int a = 3;

int c = a << 2 + 1;

will produce a different result than:

int c = (a << 2) + 1;

The first will evaluate to c = a<<3.

Discuss operator precedence in C programming with examples ​-example-1
User Chrixm
by
4.5k points