Home › C++ Tutorial › C++ errors and debugging
C++ errors and debugging
Types of mistakes.
Syntax errors stop compiling, runtime errors crash the program, logic errors give wrong answers. Debug with cout prints, compiler warnings (-Wall) and a debugger such as gdb.
Example code
// Compile with warnings: g++ -Wall -g main.cpp
#include <iostream>
using namespace std;
int main() {
int x = 5;
cout << "x = " << x << endl; // debug print
return 0;
}