ProgrammingVery hardProduct company OA
What is printed?
What is printed?
enum { RED = 2, GREEN, BLUE = GREEN + 4, N };
int a[] = { [RED] = 5, [BLUE] = 1, 9, [GREEN] = 6, 4 };
printf("%zu %d %d %d %d", sizeof a / sizeof a[0], a[4], a[8], a[5], N);- A. 8 4 0 0 8
- B. 5 4 9 0 4
- C. 9 0 9 4 8
- D. 9 4 9 0 8
Correct answer: D. 9 4 9 0 8
Enumerators continue from the previous value: GREEN = 3, BLUE = 7, N = 8. In an initialiser, an element without a designator goes to the position right AFTER the previous one: 9 follows [BLUE] and lands in a[8]; 4 follows [GREEN] and lands in a[4]. The array size is the highest initialised index + 1 = 9, and untouched elements such as a[5] are zero. '8 …' assumes the size is N.
More C Programming questions
- Assume 8-bit char, 16-bit unsigned short and 32-bit int. What is printed? c int big = 300; unsigned char uc = big; unsigned short us = -1…
- What is printed? c int slot(int i) { static int box[3]; return &box[i % 3]; } int main(void) { slot(0) = 5; slot(4) = 7; int p = slot(3)…
- What is printed? c #define A 1 #define B #if defined(B) && A + C #define X 10 #else #define X 20 #endif #undef A #ifdef A #define Y 1…
- An array of int that may contain any values from INTMIN to INTMAX is sorted with qsort. With int x = (const int )a, y = (const int )b…
- What is printed? c int a[] = {4, 8, 15, 16, 23}; printf("%zu %d", sizeof(a) / sizeof(a[0]), a[sizeof(a) / sizeof(a[0]) - 1]);
- What is printed? c printf("%d %d %d", 5 > 3 && 2 > 4, !0, !!7);