ProgrammingVery hardProduct company OA · GATE CS
On an LP64 system (8-byte pointers), what is printed?
On an LP64 system (8-byte pointers), what is printed?
printf("%zu %zu", sizeof("abc"), sizeof("abc" + 1));- A. 4 4
- B. 4 3
- C. 4 8
- D. 3 2
Correct answer: C. 4 8
A string literal is an array, here char[4] including the '\0', and sizeof applied directly to it gives 4. In "abc" + 1 the array first decays to char *, so the operand is a pointer and sizeof gives 8. '4 3' assumes the arithmetic just drops a character.
More C Programming questions
- On an LP64 system (8-byte pointers), what is printed? c char a[] = "cat", b = "cat"; printf("%d %d", strcmp(a, b) == 0, sizeof(a) ==…
- What is printed? c struct P { int x; int y; }; struct P a[3] = {{1, 2}, {3, 4}, {5, 6}}; struct P p = a; int r1 = (p + 2)->x; int r2 =…
- With a C99 (or later) compiler, what is printed? c int ds(int n) { return n == 0 ? 0 : n % 10 + ds(n / 10); } int main(void) {…
- What is printed? c int f(unsigned x) { int c = 0; while (x) { c += x & 1; x >>= 2; } return c; } int main(void) { printf("%d", f(0xFF) +…
- What is printed? c #define VAR(n) v##n #define PRINT(n) printf("%d ", VAR(n)) int v1 = 10, v2 = 20, v12 = 30; PRINT(1); PRINT(1 + 1)…
- Assume 32-bit unsigned int. What is printed? c unsigned int n = 5; int count = 0; for (unsigned int i = n; i < n + 3; i -= 2) count++…