ProgrammingHardProduct company OA
With 4-byte int, what is printed?
With 4-byte int, what is printed?
int a[4];
memset(a, 1, sizeof a);
printf("%d", a[0]);- A. 1
- B. 4
- C. 257
- D. 16843009
Correct answer: D. 16843009
memset writes the value 1 into every byte, not every int. Each int becomes 0x01010101 = 16843009. memset is only safe for setting ints to 0 (or -1, all bits one).
More C Programming questions
- What is printed? c struct N { int v; struct N nx; }; struct N c = {3, NULL}, b = {2, &c}, a = {1, &b}; struct N prev = NULL, cur = &a, nx…
- After this code, what does buf hold and what is n? c char buf[20]; int n = sprintf(buf, "%04d|%.2s", 7, "xyz");
- What is printed? c int c = 0; for (int i = 0; i < 5; i++) { for (int j = 0; j < 5; j++) { if (j == i) continue; if (j > i + 1) break; c++…
- Which of the following is NOT allowed in C?
- What is printed? c int cnt(int n, int last) { if (n == 0) return 1; return cnt(n - 1, 0) + (last ? 0 : cnt(n - 1, 1)); } int main(void) {…
- On a two's-complement machine, what is printed? c int a = 5; printf("%d %d %d", !a, ~a & 0xF, !!a + !~-1);