ProgrammingVery hardGATE CS · Campus placements
uint16_t s = 0; for (int i = 1; i <= 1000; i++) s += i; What is s at the end?
- A. 500500
- B. 41748
- C. 0
- D. 65535
Correct answer: B. 41748
Each addition wraps modulo 65536, and the final value equals 500500 mod 65536 = 41748. The loop finishes with a defined unsigned value, not the true sum.
More C Programming questions
- #define CAT(a,b) a##b. After int CAT(num, 2) = 7; what does printf("%d", num2 2) print?
- int a = 1 ? 2 : 3 ? 4 : 5; What is a?
- char p = "xyz"; char a[] = "xyz"; a[0] = 'Q'; printf("%s", a); What is printed?
- char s[4] = "abc"; What is sizeof s?
- Ackermann-style recursion: A(0,n) = n + 1 and A(m,0) = A(m-1,1), with A(m,n) = A(m-1, A(m,n-1)). What is A(1,5)?
- How many ordered ways are there to write 10 as a sum of parts equal to 1, 3 or 4, where the order of the parts matters?