← Quiz: C Data Types and Operators: all 10 questions
Quiz: C Data Types and Operators · Question 6 of 10
What does this print? (code)
What does this print?
#include <stdio.h>
int main(void) {
int a = 7, b = 2;
float f = a / b;
printf("%.1f %.1f\n", f, (float)a / b);
return 0;
}
- A.3.5 3.5
- B.3.0 3.5
- C.3.0 3.0
- D.3 3.5
Answer & explanation
Correct answer: 3.0 3.5
a / b is integer division (3), which is then stored as 3.0; casting a first makes the division 7.0 / 2 = 3.5.
Can you get the rest right without peeking?
Take the timed Quiz: C Data Types and Operators quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →