Multiple choice

void crash (void) {
printf(got here); *((char *) 0) = 0; } The function crash(), defined above, triggers a fault in the memory management hardware for many architectures. Which one of the following explains why got here may not be printed before the crash?

  1. The C standard says that dereferencing a null pointer causes undefined behavior. This may explain why printf() apparently fails.

  2. If the standard output stream is buffered, the library buffers may not be flushed before the crash occurs.

  3. printf() always buffers output until a new line character appears in the buffer. Since no newline was present in the format string, nothing is printed.

  4. There is insufficient information to determine why the output fails to appear. A broader context is required.

  5. printf() expects more than a single argument. Since only one argument is given, the crash may actually occur inside printf(), which explains why the string is not printed. puts() should be used instead.

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

Standard output is typically line-buffered or fully buffered. If the program crashes before a newline is encountered or the buffer is flushed, the output may not appear.