Learn
Errors
Compile-time Errors

When we are writing C++ programs, the compiler is our first line of defense against errors.

There are two types of compile-time errors:

  • Syntax errors: Errors that occur when we violate the rules of C++ syntax.
  • Type errors: Errors that occur when there are mismatch between the types we declared.

Some common syntax errors are:

  • Missing semicolon ;
  • Missing closing parenthesis ), square bracket ], or curly brace }

Some common type errors are:

  • Forgetting to declare a variable
  • Storing a value into the wrong type

Here’s an example of a compile-time error message:

$ g++ example.cpp example.cpp: In function 'int main()': examplecpp:5:11: error: invalid conversion from 'const char*' to 'int' [-fpermissive] int x = "hello";

The compiler will tell us where (line number) it got into trouble and its best guess as to what is wrong.

Instructions

1.

Try compiling the code and find the compile-time error in millionaire.cpp.

Folder Icon

Take this course for free

Already have an account?