1,893 views

Consider the following C code:

{ int a=5, b=9;

float r;

r=b/a; }

What is the value of r ?

(A) 1.8    (B) 1.0

(C) 2.0    (D) 0.0

### 1 comment

B is correct here.

In C, the type of the result depends on the types of the operands and is independent of the type of the variable to which the result is assigned.  Here, the operands to "/" operator are both integers, and hence the result is $\lfloor \frac{9}{5} \rfloor = 1$.

PS: If the types of the operands are not the same; the smaller ranked one is promoted to the larger one and result will have that type.
by
9/5 returns 1 and 9%5 returns 4.So option B