Thursday 16 August 2012

Errors in C

Errors (also known as bugs) are common while writing a program. The errors should be detected and removed, or else, the whole set of statements of a program will simply produce wrong result. Errors can be detected only while running the program.

In C errors are of 3 types - Syntax Error , Logical Error and Run-time Error .

  • Syntax Error : These are generally typing error of the statements that are not according to the grammatical rules or syntax of the language. 
  • Syntax error will definitely occur and the program will not compile if semicolon (separator) is not placed at the end of the statement.
  • Logical Error : It occurs due to entering logically incorrect statement in the program.
  • If an addition program is instructed to do subtraction, it will compile, but produce a wrong output. This is logical Error.
  • Run - time Error : A program free of syntax and logical errors, may not produce result due to run - time errors, which usually occur due to the following reasons : 
  • Statements instructing to divide a number by zero.
  • Statements instructing to find logarithm of a negative number. 
  • Statements instructing to find the square root of a negative number. 


Logic Building - Examples

Let's Discuss some Examples.

1. Display the value of a variable :
Pseudocode in English :
  • Declare a variable.
  • Take the input.
  • Display the variable.
Flowchart : 
  • Declare three numeric variable.
  • Take the inputs from user.
  • Perform the sum.
  • Display the result.
Flowchat :


See here check is intentionally skipped.
  • Here int is data type in C , it stands for Integers. ( It will be discussed later in greater detail )