Course Content
History of C Language
0/2
Basic Structure of C Program
0/1
Types of Errors
0/1
Language Fundamentals
0/1
Data Types and Modifiers
0/1
Programming with C Language
About Lesson

Saving C Program:

C program can be edited, compiled and run in many platforms like DOS, UNIX or directly in the editor provided by their flavor of compiler (like Turbo C).  C program code (Source Code) to be saved with file extension .c

COMPILING C PROGRAM:

Compiling means converting Source code (program code written in high level language) into object code (code format understandable by Computer).  Compilation process checks the source code for syntax or semantic errors, reports about errors and finally creates object code file with extension .obj only when no syntax or semantic errors.

Syntax errors are the errors occurred when a statement in the program had not been written by following syntax rules of C language.

Example :

/*program to print a message*/

#include<stdio.h

main()

{

            Printf(“This is C program\n”)

When compiled the following errors occur:

Error test.c 1: No file name ending

Error test.c 5: Statement missing ;

Error test.c 6: compound statement missing }

Semantic errors are displayed as warnings and do not break compilation process. 

Example: if you have declared a variable and not used the same in the program, compiler gives a warning that “Code has no effect”

LINK AND RUN C PROGRAM:

Linking is the process of getting included header files to tie with current program.  The output of Linking is the executable program file with extension .exe

LINKER ERRORS

Executable file can only be created when there are no linker errors.  Linker errors occur when certain header file is not found.

LOGICAL AND RUNTIME ERRORS:

Logical Errors cannot be found out by Compiler or Linker.  This kind of errors are called logical errors can only removed by debugging.  Debugging is the process of checking program step by step and verifies the results.

Example:

/*Program to compute average of three numbers*/

#include

main()

{

            int a=10,b=5,c=20,sum,avg;

            sum=a+b+c;

            avg=sum/3;

            printf(“The average is %d\n”,avg);

}

This program gives output as 8 but actual average is 8.33 because of rounded off error.  To rectify the error we have declare avg as float data type.

Another kind of Errors called Run time Errors like program do not producing the result, execution stops in between and error message flashes on the screen.

Example:

/*program to divide a sum of two numbers by their difference*/

#include

main()

{

            int a=10,b=10;

            float c;

            c=(a+b)/(a-b);

            printf(“The value of the result is %f\n”,c);

}

This program gives run time error as Divide by Zero

You cannot copy content of this page