Redirected
edited by
124 views
0 votes
0 votes

Consider the following $\mathrm{C}$ code :

{int a = 5, b=9;
float r;
r= b /a ;}

What is the value of $\text{r}$ ?

  1. $1.8$
  2. $1.0$
  3. $2.0$
  4. $0.0$

     

edited by

2 Answers

Best answer
2 votes
2 votes
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

Related questions

0 votes
0 votes
1 answer
2
admin asked Jan 6
78 views
The complexity of Kruskal's minimum spanning tree algorithm on a graph with ' $n$ ' nodes and ' $e$ ' edges is :$\mathrm{O}(n)$$\mathrm{O}(n \log n)$$\mathrm{O}(e \log n)...
0 votes
0 votes
1 answer
3
admin asked Jan 6
86 views
If a code is t-error correcting, the minimum Hamming distance is equal to :$2 t+1$$2 t$$2 t-1$$t-1$
0 votes
0 votes
3 answers
4
admin asked Jan 6
172 views
The set of positive integers under the operation of ordinary multiplication is :not a monoidnot a groupa groupan Abelian group