297,849 views
40 votes
40 votes
Discuss operator precedence in C programming with examples ​

User Echristo
by
2.5k points

1 Answer

11 votes
11 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 James Broadhead
by
2.9k points