Types of errors in C++ (Day Four)

Program Flow So, the compiler compiles expanded source code to assembly source code successfully if the syntax or meaning of program is correctly written. So, the Compiler job is to analyze the program code for “corectness”.  If the compiler does not detect any error, then syntax of program is correct, otherwise it may detect different types of errors.

Various types of errors in c++ is as follows –

  • Syntax Errors – These errors occurs when rules of programming are not followed. or when a grammatical rule of C++ is violated. For example, in English, we have (,)-comma, (.)- periods etc So, Syntax refers to the set of rules or simply rules, that governs the construction of valid statements in a language.
  • Semantics Errors – occurs when statements are not meaningful. For example, ‘Ram feeds food’ is syntactically (syntax rules of English Grammar) and semantically (semantic rules of English grammar) correct as it has some meaning. But ‘Food feeds Ram’, is syntactically correct but semantically wrong. SO, Semantics refers to the set of rules which gives the meaning of a statement.
  • Type Errors – C++ has associated data type for all types of data. For storing whole numbers, C++ has integer data type, For character and string – char data type, For fractional data- float data type is provided. So Type error is signaled by the compiler if data/value of wrong or unexpected type is passed.
  • Run Time Errors – occurs during execution of the program. These are the errors which a compiler cannot detect in the program during a program compilation. For example, divide by zero, or if enough memory is not available etc. Run Time Errors are also called Execution Errors. 
  • Logical Errors – These errors are also not detected by compilers. however, the syntax and semantics of the whole program is correct. These are the errors which produces incorrect results in a program during execution.
Types Of errors in C++
Note : A compile detects only syntax errors, semantics errors and type errors. Logical and run time errors can be detected only by tracing the program line by line
]]>

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top