argc/argv, errno & assert in C
From the C cheat sheet · Command-line & Error Handling · verified Jul 2026
argc/argv, errno & assert
Read arguments and handle errors.
c
// Quick Reference
int main(int argc, char *argv[]) {
// argv[0] = program name, argv[1..] = args
}
#include <errno.h>
perror("open failed");
assert(x > 0);💡 argv[0] is the program name; real arguments start at argv[1], counted by argc.
⚡ C has no exceptions - functions signal failure via return values and the global errno.
📌 perror / strerror(errno) turn an error code into a human-readable message.
🟢 assert catches bugs during development; defining NDEBUG compiles all asserts out.
argc-argverrnoassert