in Programming
1,893 views
0 votes
0 votes

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

in Programming
1.9k views

1 comment

B is correct here.
0
0

2 Answers

2 votes
2 votes
Best answer
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.
selected by
by
0 votes
0 votes
9/5 returns 1 and 9%5 returns 4.So option B

Related questions