Common Programming Mistakes in C++

C++

C++ is the most popular programming language because it is powerful, efficient and standardized. It is a complex language and even experienced programmers can make mistakes that can cause corrupted data  or program crashes.

Here are some common C++ programming mistakes that can cause these issues:

  • Undeclared functions or variables. Always remember to declare a function or variable so the compiler will know what it means.
  • Uninitialized variables. It is a common misconception that variables in C++ are initialized to zero.
  • Setting variables to uninitialized values. Once a variable has been assigned a value, it will be the same until values are reassigned.
  • Misspelling variables or functions. Typos in the variable/function names, including using the case of letters inconsistently, will lead to problems. 
  • Forgetting to use a semicolon, usually at the end of a class declaration. Remember that semicolons only go at the end of complete statements.
  • Adding extra semicolons. Semicolons do not go at the end of loops, function declaration, or #include, if and switch lines.
  • Using one equal sign (=) instead of two (==) to check for equality.  A single equal sign (the assignment operator) assigns the value on the right side to the variable on its left. To see if the values on both sides of the operator are equal, use two equal signs.

These mistakes are common among beginner or novice programmers, but sometimes even advanced C++ users make these mistakes. What other mistakes have you made using C++? Leave a comment below or tweet us at @ShinetechUS.

Photo credit: isipeoria

Categories: 
up
0 users have voted.

Add new comment