ProgrammingHardProduct company OA
Assume C99 or later. What is printed?
Assume C99 or later. What is printed?
void f(int n, int a[][n]) { printf("%zu", sizeof a[0] / sizeof a[0][0]); }
int main(void) { int m[2][5]; f(5, m); }- A. 2
- B. 10
- C. 5
- D. 1
Correct answer: C. 5
a is a pointer to a variable-length row of n ints, so a[0] is a whole row whose size is computed at run time: 5 ints. That is how C99 lets functions take 2-D arrays whose column count is not fixed at compile time.
More C Programming questions
- What is printed? c int c = 0; for (int i = 1; i <= 10; i++) for (int j = i; i j <= 10; j++) c++; printf("%d", c);
- What does z("abcdef") print? c void z(const char s) { if (!s) return; putchar(s); z(s + 2); if (s[1]) putchar(s[1]); }
- Does this function compile, and what does it do? c struct S { int p; }; void f(const struct S s) { s->p = 5; }
- On a two's-complement machine, what is printed? c int x = 5; printf("%d %d", -~x, ~-x);
- What is printed? c const char s = "ab cd"; printf("%zu", strlen(s));
- On an LP64 system (32-bit int, 64-bit long), what is printed? c printf("%zu %zu", sizeof(2147483647), sizeof(2147483648));