ProgrammingHardTCS NQT · Infosys
Would the product of 50000 and 50000 overflow a 32-bit int? The program checks with a 64-bit product. What is printed?
Would the product of 50000 and 50000 overflow a 32-bit int? The program checks with a 64-bit product. What is printed?
#include <stdio.h>
int main(void) {
long long p = (long long)50000 * 50000;
printf("%d", p > 2147483647LL);
}- A. 0
- B. 2
- C. 3
- D. 1
Correct answer: D. 1
The product is 2500000000, which is larger than INT_MAX = 2147483647, so the comparison is 1.
More C Programming questions
- What is printed? c #include <stdio.h> int main(void) { const char s = "112233"; int count[10] = {0}; for (const char p = s; p; p++)…
- What is the trace of the matrix product A B, where A = {{1, 2}, {3, 4}} and B = {{5, 6}, {7, 8}}? Compute with this program. c #include…
- How many elements of {0, 2, 1, 3, 4, 7, 6} equal their own index? Count with this program. c #include <stdio.h> int main(void) { int a[] =…
- What is printed? c #include <stdio.h> int main(void) { int a[] = {2, 7, 1}; int e = a + sizeof a / sizeof a[0] - 1; printf("%d", e); }
- What is printed? Assume int is 4 bytes. c #include <stdio.h> int main(void) { int a[4]; printf("%ld", (long)((char )&a[2] - (char…
- How many valid strings of n = 3 pairs of parentheses are there? The program counts them recursively. What is printed? c #include <stdio.h>…