C Language: perror function(Print Error Message)

In the C Programming Language, the perror function write an error message to the stderr stream in the following format:

string: error-message


The syntax for the perror function in the C Language is:

void perror(const char *s);

Parameters or Arguments


The string portion of the error message written to stderr.


The error-message portion of the error message written to stderr is equivalent to the value returned by the strerror function with the call strerror(errno).


The perror function returns a nonzero value if the error indicator is set. Otherwise, it returns zero.

Required Header

In the C Language, the required header for the perror function is:

#include <stdio.h>

Applies To

In the C Language, the perror function can be used in the following versions:

  • ANSI/ISO 9899-1990

stdio.h Functions