Error handling in C

In C programming language we have error.h header file which is used to point out any error and return it in a function call. A C program returns -1 or NULL value if any error occurs. A global variable errno is declared and is set with the error code. Thus we can use the return value to check any error in the program. The following functions are used in C language to represent error.

  1. perror is used to return the string to represent current error.
  2. strerror is used to return a pointer to string to represent current error. It is defined in string.h.