Kinds of errors
Theory and problem statement
Machine translation, not yet reviewed by a native speaker.
Errors in C come in three kinds, and they're caught at different stages.
1. Compile errors — the program doesn't build: a typo, a forgotten ;, an unknown variable. The compiler points to the file and the line: main.c:7:5: error: expected ';'. Read the first error: the rest are often its consequences.
2. Runtime errors — the program built, but it crashes: division by zero, dereferencing NULL, going out of an array's bounds (Segmentation fault).
3. Logic errors — the program runs, but gives the wrong result. These are the most treacherous: the computer doesn't know about them.
A separate category is undefined behaviour (UB). These are actions whose result the C standard doesn't define: overflowing an int, reading an uninitialised variable, going out of bounds. A program with UB may work on your computer and break on another one, or after the optimisation flags change.
Warnings aren't errors, but they almost always point to a bug. Compile with -Wall -Wextra and get the number of warnings down to zero.
Task. The program doesn't compile because of three errors. Fix them so that it reads two numbers and prints their sum.
Sign up for free to solve this task right in your browser: code editor, running, test checks and hints.