Introduction to C language
Structure of a 'C' Program




Documentation section
Link section or pre processor commands
Definition section
Global declarations

main()
{

local variables
statement sequence

}

function 1(argument list)
{

local variables
statements sequence

}

function n(argument list)
{

local variables
statements sequence

}

Documentation section:- It is the area where we write the comments. Link section:- If we want any C command to work you have to link some files which enables those commands to work in our program. Those files are known as header files and we have to link them to our program using #include. We have different types of header files like stdio.h, conio.h, string.h, graphics.h , math.h etc.,

If we want any mathematical function to be evaluated like power, sin, tan, cos, sqrt etc. we have to include math.h in our program.

The stdio.h header file contains functions to perform basic input and output. Definiton section:- In this section, we define names to the constants. These values cannot be changed in our program. While giving names to the constant we have to give them in UPPER case, so that you can distinguish which is a variable and which is a constant. It is defined by using the #define

Eg: #define A 45

Global declarations:- When we want the variable values to be available outside the main program also then we have to declare them in this section. These variable can be accessed anywhere in the program.

Main():- This is a special function name and should be included in the program. This is the first function that will be executed when you run a program.

ENTERING INTO 'C'

You have to go to Dos prompt and at the c:\> you have to change the directory to turboc2 and give 'tc' command. This will take you to the editor where you can write a C program. printf():- This is a function which is used to display the messages on the screen and also used to display the values in the variables using the respective format specifiers.

Syntax: printf( "control string ", arguments);

Eg: printf("Hello");

printf("The value is %d", a);
scanf():- It is used to accept the values through the keyboard during run time.
Syntax:- scanf("control string", arguments);
Eg: scanf("%d%d",&a,&b);
Here in scanf(), you should not use any spaces or special characters in the middle of format specifiers. The '&' symbol here is known as address of operator and the value we accept is stored in the address of the variable. After writing a C program in editor, you have to save the file, by default, file will be noname.c and it is renamed with the file name you give i.e for example 'my_file', by saving it. After saving a file, you have to compile it, by pressing Alt+F9 or using compile option from compile menu. It will convert all the source program(user program) into object code (machine language) and gives the errors if present any in the program. While compiling it, it creates a file with the extension .obj with the same name as the filename. After removing the errors finally, it will create an executable file with the same name as the file and with extension as .exe. To get the output of the program to have written, you have to run the file. This you can do by pressing, Ctrl+F9 or using 'run' option from 'run' menu. After executing the file, you are again brought back to the program. To see the result of your program, you have to press Alt+F5 to go to user screen. If you give a getch() command at the end of program before the ending brace, there is no need for you to use Alt+F5. Using the executable file, you can run your program from the dos prompt also even if you don't have .c and .obj files. Along with these 3 files, you will get another file, which will contain the source program and with the extension .bak and with the same name as the file name. This file is known as backup file. Even you by mistake delete the source file, still you can get it by using this backup file.



 
-----------------------------------------------------------------------------------------
please mail comments to vgdarur@gmail.com
 

 

www.iforerunner.com