ProgrammingHardWipro · Accenture · Capgemini pattern

What is the output of this C program (assume a typical 64-bit platform: int 32 bits, long and pointers 64 bits, double 8 bytes, structs aligned to their widest member with no packing pragma)? #include <stdio.h> int main(void) { float f = 7 / 2; float g = 7.0 / 2; printf("%.1f %.1f", f, g); return 0; }

  1. A. 3.0 3.5
  2. B. 3.0 3.0
  3. C. 3.5 3.5
  4. D. 3.5 3.0

Correct answer: A. 3.0 3.5

7 / 2 is integer division (both operands int) giving 3, which is then converted to float 3.0; 7.0 / 2 is floating-point division giving 3.5.

More C Programming questions

Exams that ask this topic