0
0
Cprogramming~5 mins

Using errno in C - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is errno in C programming?
errno is a global variable set by system calls and some library functions in C to indicate what error occurred during the last operation.
Click to reveal answer
beginner
How do you include errno in your C program?
You include the header <errno.h> which declares errno and error codes.
Click to reveal answer
intermediate
Why should you set errno to 0 before a function call?
Setting errno to 0 before a function call helps to check if the function actually changed errno to indicate an error.
Click to reveal answer
beginner
What function can you use to get a human-readable string for the current errno value?
You can use strerror(errno) to get a readable error message describing the error.
Click to reveal answer
intermediate
Is errno reset to 0 automatically after a successful function call?
No, errno is not reset automatically. It keeps its value until changed by a function that sets it.
Click to reveal answer
Which header file must you include to use errno in C?
A&lt;errno.h&gt;
B&lt;stdio.h&gt;
C&lt;stdlib.h&gt;
D&lt;string.h&gt;
What type of variable is errno?
AStatic double variable
BLocal float variable
CPointer to char
DGlobal integer variable
What does strerror(errno) return?
AThe numeric value of <code>errno</code>
BThe last function's return value
CA string describing the error code stored in <code>errno</code>
DThe current system time
Why should you set errno = 0 before calling a function that might fail?
ATo clear the function's return value
BTo detect if the function changed <code>errno</code> indicating an error
CTo reset the program counter
DTo initialize a local variable
If a function succeeds, what happens to errno?
AIt remains unchanged
BIt resets to 0 automatically
CIt becomes -1
DIt is set to the function's return value
Explain how to use errno to detect errors after calling a system function in C.
Think about the steps to safely check errors using errno.
You got /6 concepts.
    Describe why errno is useful and how it differs from a function's return value.
    Consider the difference between error signaling and error details.
    You got /5 concepts.