3. Arithmetic operation between float and integer will always give float number. In this case, first integer will be promoted to float after that the arithmetic operation will take place.

Checkout the table below to understand these operations.

Type Conversion in Assignments

It is quite often that the variable on the left hand side of assignment operator (=) does not match the type of variable on its right hand side. In such a case, the value of the whole expression will be promoted or demoted on the basis of variable present on left hand side of assignment operator.

To make things a bit more clear lets take an example.

float a;

int b;

b=4.2;

a=3;

In the above example we are trying to store the float value (4.2) in integer variable b. So the value will be demoted to (4) and it will store in the integer variable. Same thing will happen with 3. As 3 is an integer, so it will be converted to float (3.00000) and then it will be stored in float variable.

Complexity of the arithmetic operation doesn’t matter. You should stick with the three basic rules. That’s it.

To understand things better. Checkout below examples.

Precedence (Hierarchy) of Operators in C

BODMAS is the basic rule to solve complex arithmetic problems in maths. Unfortunately BODMAS doesn’t work in C. Suppose you wrote one expression.

x*y+z*a

So how you will solve this expression?

This way (x*y)+(z*a)

Or this way x*(y+z)*a

To solve this problem in C you have to learn about hierarchy or precedence of operators. Hierarchy of some common arithmetic operators is given below.

Some Quick Tips

Within nested parentheses, arithmetic operations will be done according to above priority. Expression under innermost parentheses will be solved first.

It is advised to use parenthesis in the program carefully. You should type both parentheses first ( ). After that start typing expression inside it. This will remove the errors caused by missed parenthesis.

Associativity of Operators in C

Associativity of operators is used when two operators of equal priority makes a tie. In that case the arithmetic operation is solved using the associativity table of C language.

Complete table of precedence and associativity of operators in C is given below.