ProgrammingVery hardProduct company OA
Assume 32-bit int and 64-bit long long. What is printed?
Assume 32-bit int and 64-bit long long. What is printed?
int n = -1;
unsigned int len = 3;
long long big = -1;
printf("%d %d %d %d", n < len, n < (int)len, big < len, (n + len) == 2);- A. 1 1 1 1
- B. 0 1 0 1
- C. 0 1 1 1
- D. 0 1 0 0
Correct answer: C. 0 1 1 1
In int vs unsigned int the int is converted to unsigned: −1 becomes 4294967295, so n < len is 0 (the classic loop-bound bug); with the cast it is 1. long long can represent every unsigned int value, so there len is converted to long long and −1 < 3 is 1 – the rule depends on rank, not just on 'unsigned wins'. n + len is computed modulo 2³² = 2. Output 0 1 1 1.
More C Programming questions
- Assume a 64-bit LP64 ABI (4-byte int, 8-byte pointers and double, natural alignment). What is printed? c struct A { char c; double d; int…
- What is printed? c #define SQ(x) x x #define MIN(a, b) ((a) < (b) ? (a) : (b)) int calls = 0; int next(void) { return ++calls; } int…
- What is printed? c #define N 4 #define STR(x) #x #define XSTR(x) STR(x) #define CAT(a, b) a##b #define XCAT(a, b) CAT(a, b) int NN = 9…
- Which of the numbered statements violate a constraint (i.e. must be rejected by the compiler)? c typedef char strt; #define STRM char char…
- What is printed? c int g = 1; int f(int n) { static int s = 10; int g = n; s += g; { extern int g; g += s; } return s; } int main(void) {…
- What is printed? c int i = 0, j = 5, k = 0; int r = (i++ || j++) && (k++, i + j > 1) ? i++ : (j += 2, k); printf("%d %d %d %d", r, i, j, k);