ProgrammingHardProduct company OA
With 4-byte int, what is printed?
With 4-byte int, what is printed?
int n = 0;
int f(void) { n++; return 1; }
int main(void) {
size_t s = sizeof(f());
printf("%zu %d", s, n);
}- A. 1 1
- B. 4 0
- C. 4 1
- D. 8 0
Correct answer: B. 4 0
sizeof only needs the type of its operand, and f() has type int, so the call is never made and n stays 0. (The one exception is a variable-length array, whose size must be computed at run time.)
More C Programming questions
- What is printed? c int n = 3, s = 0; while (n--) s += n; printf("%d %d", s, n);
- Assume ASCII. What is printed? c int cmp(const void a, const void b) { return strcmp((const char )a, (const char )b); } int main(void) {…
- What is printed? c int g[3][3] = {{1, 3, 1}, {1, 5, 1}, {4, 2, 1}}; int mp(int r, int c) { if (r == 0 && c == 0) return g[0][0]; if (r < 0…
- What is printed? c unsigned next(unsigned x) { unsigned c = x & -x, r = x + c; return (((r ^ x) >> 2) / c) | r; } int main(void) {…
- What is printed? c const char s = "abcabcab"; const char p = strstr(s, "cab"); printf("%td %s %td", p - s, p + 3, strstr(p + 1, "cab") - s);
- What is printed? c struct A { int v[3]; }; struct A make(void) { struct A a = {{1, 2, 3}}; return a; } int main(void) { struct A x =…