VOOZH about

URL: https://www.geeksforgeeks.org/c/perror-in-c/

⇱ perror() in C - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

perror() in C

Last Updated : 3 Feb, 2025

In C, perror() is a built-in function used to display a custom text description of the error code, which is stored in the system variable errno.

Example:


Output

An error occurred: No such file or directory

Syntax

clearerr() is a standard library function defined in <stdio.h> file.

perror("message");

This function does not return any value.

Examples of perror()

The following examples demonstrate the use of perror() in our C programs:

Handle Memory Allocation Error


Output

Memory allocation failed: Cannot allocate memory

Handle Insufficient Permission Error


Output

Error creating file: Permission denied
Comment
Article Tags: