ProgrammingVery hardTCS NQT · Infosys
What is printed?
What is printed?
#include <stdio.h>
int main(void) {
int v[] = {-1, -2, -3};
unsigned s = 0;
for (int i = 0; i < 3; i++) s += (unsigned)v[i];
printf("%u", s);
}- A. 4294967291
- B. 4294967290
- C. 4294967289
- D. 4294967280
Correct answer: B. 4294967290
Converting each negative value to unsigned adds 2^32 - 1, 2^32 - 2 and 2^32 - 3. The total wraps to 2^32 - 6 = 4294967290.
More C Programming questions
- How many zero bits are there in the low eight bits of 0xF0? Count them with this program. c #include <stdio.h> int main(void) { unsigned x…
- What is printed? c #include <stdio.h> #include <stdlib.h> #include <string.h> int cmp(const void a, const void b) { const char x = (const…
- How many ordered ways are there to write 10 as a sum of 1s and 4s? Compute with this program. c #include <stdio.h> int f(int n) { if (n ==…
- What is printed? c #include <stdio.h> int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } int main(void) { printf("%d"…
- What is printed? c #include <stdio.h> int rev(int n, int acc) { return n == 0 ? acc : rev(n / 10, acc 10 + n % 10); } int main(void) {…
- What is printed? The program checks whether the low four bits of each argument form a binary palindrome. c #include <stdio.h> unsigned…