Programming Fundamentals · Interview question

What's the difference between stdout and stderr, and when do you use each?

A strong answer

stdout (file descriptor 1) is for the program's normal output, the data the user actually asked for. stderr (file descriptor 2) is for diagnostics: errors, warnings, progress messages. They're separate streams so the user can redirect them independently, ./myprogram > out.txt sends stdout to a file but leaves errors visible on the terminal. They share the terminal by default, which is why beginners think they're the same thing. Pipelines work the same way: ./a | ./b only pipes stdout, so error messages from a don't pollute b's input.

What a weak answer sounds like

You know the answer. Do you know what gets you dinged?

Pro breaks down the answer most candidates actually give to this question — and the specific reason an interviewer marks it down. It’s the difference between sounding correct and sounding senior, on all 472 questions.

From the lesson

Input & Output

How a program talks to the outside world. printf and scanf in C: format specifiers, common traps, and why the return value matters.

More Input & Output questions

Browse all 472 interview questions
What's the difference between stdout and stderr, and when do you use each? | EmbeddedPrep.io