How does C typically report errors in standard functions?
A
By throwing exceptions B
By using error return values C
By crashing the program D
By logging to a file
Analysis & Theory
C handles errors using return values like `-1`, `NULL`, or `EOF`.
Which global variable is used to store error codes in C?
A
error B
errno C
errcode D
E
Analysis & Theory
`errno` is a global integer that stores the error code set by library functions.
What header file must be included to use `errno`?
A
stdio.h B
stdlib.h C
string.h D
errno.h
Analysis & Theory
To access `errno` and symbolic constants like `EACCES`, include `errno.h`.
Which function prints a human-readable error message based on `errno`?
A
print_error() B
perror() C
showerr() D
strprint()
Analysis & Theory
`perror()` prints a custom message followed by the system error message.
Which function converts `errno` into a readable string?
A
errstr() B
strerr() C
strerror() D
perror()
Analysis & Theory
`strerror(errno)` returns a pointer to a human-readable string describing the error.
What is the value of `errno` if no error has occurred?
A
0 B
-1 C
1 D
Undefined
Analysis & Theory
`errno` is usually `0` before any error occurs, though it’s not reset automatically.
How do you manually reset `errno`?
A
reset_errno() B
seterr(0) C
errno = 0; D
clear(errno)
Analysis & Theory
You can reset `errno` by directly assigning `0` to it.
What is typically returned by C functions to indicate failure?
A
1 B
0 C
NULL or -1 D
EOF only
Analysis & Theory
Functions return `-1`, `NULL`, or `EOF` to signal failure, depending on the function.
Which of these is **not** a standard error constant defined in `errno.h`?
A
EACCES B
EINVAL C
EFREE D
ENOMEM
Analysis & Theory
`EFREE` is not a valid standard `errno` constant.
What does this code do?
```c
FILE *f = fopen("no.txt", "r");
if (!f) perror("File open error");
```
A
Closes file B
Prints success C
Prints file open error D
Does nothing
Analysis & Theory
If `fopen` fails, `f` is NULL and `perror()` prints the reason using `errno`.