ProgrammingHardTCS NQT · Infosys
On an LP64 system (8-byte pointers), what is printed?
On an LP64 system (8-byte pointers), what is printed?
char a[] = "cat", *b = "cat";
printf("%d %d", strcmp(a, b) == 0, sizeof(a) == sizeof(b));- A. 0 0
- B. 1 0
- C. 1 1
- D. 0 1
Correct answer: B. 1 0
strcmp compares contents, which match, so the first test is 1. a is an array of 4 chars (sizeof 4) while b is a pointer (sizeof 8), so the second test is 0. Arrays and pointers behave alike in expressions but not under sizeof.
More C Programming questions
- 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++…
- What is printed? c char w[][6] = {"red", "green", "blue"}; printf("%zu %zu %zu", sizeof(w), sizeof(w[1]), strlen(w[1]));