What is perror in C?
The perror() function displays the description of the error that corresponds to the error code stored in the system variable errno.
errnois a system variable that holds the error code referring to the error condition. A call to a library function produces this error condition.
Syntax
Parameter
str:The pointer to a null-terminated string. This string should contain an explanatory message about the error.
Code
The perror() function shows the output in the following order:
- The contents of the string pointed to by specified pointer i.e.,
str - Followed by “:”
- Then appends the error message corresponding to the error code in variable
errno
main.c
file.txt
Hello
Free Resources
Copyright ©2026 Educative, Inc. All rights reserved