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]);
  1. A. 1
  2. B. 4
  3. C. 257
  4. 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

Exams that ask this topic