perror function(Print Error Message) in C Language – example and detail

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

string: error-message


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

void perror(const char *s);

Parameters or Arguments

s The string component of the error message written to stderr.

Note The error-message element of the error message written to stderr is equal to the price lower back through the strerror function with the call strerror(errno).


The perror characteristic 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 feature can be used in the following versions:

ANSI/ISO 9899-1990

Similar Functions

Other C functions that are similar to the perror function:

strerror function <string.h>