Tuesday 22 May 2012

Constant Macro, Delimiters, Statement Terminator

Dear Members,
    In this lesson we give you a concept about Constant Macro, Delimiters, Statement Terminator and its importance in C program.

  • Constant Macro:-
                        The 'define' directive is an important preprocessor directive. It is used to define a constant known constant macro. A constant macro is an identifier, which is assigned a particular constant value. The value of identifier remains constant during the execution of program.

  • Delimiters:-

                            The body of the function is surrounded by braces (or curly brackets { and } ). These braces are called delimiters. The left brace indicates the start of the body of the function, whereas the matching right brace indicates the end of the body by the function.

    • Statement Terminator:-
     
                                Every statement of C program must be terminated with semicolon ( ; ). It is called statement terminator. If any of the statement is missing the statement terminator ( ; ), the following error message will be shown by compiler during compiling process.
    Statement missing;

    Monday 21 May 2012

    Types of Errors

                     There are three types of errors that may occur while developing or writing C program. There errors are:

    1. Syntax Errors
    2. Logical Errors
    3. Runtime Errors

    • Syntax Errors:-

                        The set of rules (grammatical rules) of a programming language for writing statements of the computer program is known as syntax of the language. The program statements are written strictly according to these rules.
                        Syntax error occur when syntax of a programming language are not followed in writing the source code. The compiler detects these errors at compiling time of source code. The compiler reports a proper error message about the error.
                        The compiler does not compile a program that contain syntax errors. The syntax errors are easy to detect and remove.
        In C program, there can be many causes of syntax errors. Some examples are given below:-

    • Missing semicolon ( ; ) at the end of statement.
    • Missing any of delimiters  i.e { or }
    • Incorrect spelling of any keyword.
    • Using variable without declaration etc.



    • Logical Errors:-
                                                                
                       The errors in the logic of the program are called logical error. The compiler cannot detect logical errors. A program with logical errors is compiled (translated) and run successfully but it does not give correct result.


    • The sequence of instructions used in a program may be incorrect.
    • The mathematical formulas used in program instructions may be incorrect etc.
    The logical errors are difficult to detect. Logical errors can only be detected by examining all the units of the program one by one. It is a very time consuming and lengthy process.

    • Runtime Errors:-


     
                         The errors that occur during the execution of program are called the runtime errors. These types of errors may occur due to the following reasons.
    • When the program attempts to perform an illegal operation such as dividing a number by zero.
    • If input data given to the program is not in a correct format or input data file is not found in the specified path.
    • If hardware problem occurs such as hard disk error, or disk full or printer error etc.
    When a runtime error occurs, the computer stops the execution of program and displays an error message.

    Sunday 20 May 2012

    Bugs and Debugging

    • Bugs:-

           
                     Different errors may occur in the program. These errors in the program are called Bugs.

    • Debugging:-

           The process of finding and removing bugs (or errors) in a program is known as debugging.