ProgrammingHardIBM · Deloitte · Product Company SDE

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 sumTo(int n) { int s = 0; for (int i = 1; i <= n; i++) s += i; return s; } int main(void) { printf("%d", sumTo(10)); return 0; }

  1. A. 50
  2. B. 100
  3. C. 45
  4. D. 55

Correct answer: D. 55

sumTo(10) adds 1 through 10: 1+2+...+10 = 55.

More C Programming questions

Exams that ask this topic