Multiple choice

Which is the actual syntax to find the ratio of boys and girls in C language? (given that float ratio; int boys, girls;)

  1. ratio = boys/girls;

  2. ratio = girls/boys;

  3. ratio = (float) girls/boys;

  4. ratio = (float) boys/girls;

  5. ratio = float boys/girls;

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

Cast operator is required to convert the boys/girls calculation in decimal precision. Cast operator can be used to explicitly convert the value of an expression to a different data type.