Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C type casts and addition precedence

Tags:

c

syntax

c99

What's the precedence in the next expression?

item = (char*)heap + offset; 

Is it (char*)(heap + offset) or ((char*)heap) + offset?

like image 694
Cheery Avatar asked Jul 28 '10 15:07

Cheery


People also ask

Which has highest precedence in C?

Certain operators have higher precedence than others; for example, the multiplication operator has a higher precedence than the addition operator. For example, x = 7 + 3 * 2; here, x is assigned 13, not 20 because operator * has a higher precedence than +, so it first gets multiplied with 3*2 and then adds into 7.

Which of the operator has highest precedence?

The logical-AND operator ( && ) has higher precedence than the logical-OR operator ( || ), so q && r is grouped as an operand. Since the logical operators guarantee evaluation of operands from left to right, q && r is evaluated before s-- .

Which operator has lowest precedence in C?

4) Comma has the least precedence among all operators and should be used carefully For example consider the following program, the output is 1.


1 Answers

Cast trumps binary addition according to the precedence table.

Precedence Table

like image 199
Jacob Avatar answered Oct 02 '22 08:10

Jacob