Ad Code

Responsive Advertisement

C++ Types of errors - Learn CPP

C++ Types of errors - Learn CPP, After the translation process is completed successfully and the executable file is obtained, the program execution stage comes, but it is not certain that we will obtain the executable program in the event of errors, and that depends on the type of compiler used and according to the type of error, and it is necessary to commit programming errors in the first attempts to write programs.


C++ Types of errors - Learn CPP


Errors accompanying programs Errors


There are four types of errors that occur in the computer during the implementation of programs, some of which are discovered during the process of translation or linking, some of which occur during the execution of the program, and some of them are visible.


Fatal errors are errors that stop the compilation process or the program execution process before it finishes its work, while non-fatal errors allow programs to continue executing, but most likely cause wrong results from the program.


Most translators help us discover those errors that occur during translation, as they tell us about the error and the line number in which it was found, but the translator does not indicate to you exactly where the error is or how to correct it, but it will hint to you.


1- Compiler errors


Such errors occur when the compiler tries to compile the program, and result from a grammatical error in writing the program, such as forgetting to put a semicolon at the end of the complete statement.


2- Linker errors


Most errors of this type occur when the linker cannot find the functions or other program components that are indicated in the program.


3- Run-Time Errors


Also called semantic errors, sometimes the error is not detected except during the execution of the program, and these errors occur due to the violation of laws during the execution of the program. As the operating system collects these violations, such as division by zero, or the application of an arithmetic operation to a type that does not fit that process during the program implementation period. It is also considered a fatal error that leads to a halt in the execution process in addition to issuing a message from the operating system showing the reason, and this message can be used to locate the error in the program code.


4- Visual errors:


This is one of the errors that the translator makes due to a typographical error or omission, and these errors are considered correct for the translator, but they give wrong results.


You should also not forget that when you make any change in the program text, you must recompile it so that the change is reflected in the executable file, and this also re-confirms that your program is free of errors and their types.


Common errors in C++


  • The common mistake of leaving the semicolon (;): It is one of the many mistakes programmers make, be sure to put it at the end of the statements, or you will get an error from the compiler.
  • The common error in brackets {} is a common mistake: when writing the opening of the bracket, we must be careful to close it, otherwise, we will get an error from the compiler.
  • The common error in comment /* */: Comments are commands directed to the programmer and the compiler does not read /* here is the comment*/.
  • Confusion about not differentiating between the assignment coefficient (=) and the equalization coefficient (==) at many: Many programmers confuse the assignment coefficient and the equality coefficient and may not be able to differentiate between them, which may lead to confusion between these two operands to an error.
  • What is the difference between the coefficient of equality (==) and the assignment coefficient (=)?


1- Equality coefficient (==)


It is often used in conditional statements, for example, a==b


Here if the two numbers are true, it gives a true value, and if they are not, it gives a false value. Beginners often make this mistake.


2- Assignment parameter (=)


Changes the value on the left side of the parameter to the value on the right side (assign).