Multiple choice

What is the use of the perror() function in C?

  1. Prints the error message specified by the compiler.

  2. Works same as printf().

  3. Prints the garbage value assigned by the compiler.

  4. Works same as the gets() method.

  5. None of the above

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

The C library function void perror(const char *str) prints a descriptive error message to stderr. First the string str is printed followed by a colon then a space. Syntax : void perror (const char *str) where str is the user defined message that prints before the actual error message.