ProgrammingVery hardProduct company OA
What is printed?
What is printed?
int a[] = {10, 20, 30};
printf("%d", a[1, 2]);- A. 30
- B. 10
- C. 20
- D. Compilation error: a is not two-dimensional
Correct answer: A. 30
In C the subscript is a single expression, and 1, 2 is a comma expression whose value is 2. So a[1, 2] is a[2] = 30. (C++20 deprecated this use of the comma in subscripts; C still allows it.)
More C Programming questions
- What is printed? c struct P { int x; int y; } p = {7, 9}; int q = (int )&p; printf("%d", q);
- What is printed? c int p(int n, int m) { / ways to write n as a sum of parts <= m / if (n == 0) return 1; if (n < 0 || m == 0) return 0…
- What is printed? c printf("%#x %#o %x", 255, 8, -1 & 0xFF);
- Assume 8-bit unsigned char. What is printed? c printf("%d %d %d", (int)-3.7, (unsigned char)-1, (int)(0.1 30));
- What is printed? c int ways(int amt, int k) { static const int c[] = {1, 2, 5}; if (amt == 0) return 1; if (amt < 0 || k == 0) return 0…
- On an LP64 system (8-byte pointers, 4-byte int), what is printed? c int a[10]; printf("%zu %zu %zu", sizeof(&a), sizeof(&a), sizeof(a + 0));