C Basics
C Basics
The documentation section consist of set of comment lines giving name to program.
Link section provides instruction to the compiler to link functions to system library.
In global declaration section contains variables that are declared outside of all
functions.
Every C program must have main() function section.
The subprogram section contains all user defined functions that are called in main
function.
PROGRAMMING STYLE
Unlike some other programming language C is free_form_language. That is, C compiler
A proper indentation of braces and statements would make a program easier to read and
debug.
• The statements
a = b;
x = y + 1;
z = a + 1;
Can be written in one line as:
a = b; x = y +1; z = a+ x;
• The program: main()
{
printf(“Hello C”);
}
May be written in one line as
main( ) {printf(“Hello C”)};
EXECUTING A ‘C’ PROGRAM
Executing a C program involves series of steps. They are:
3. Linking the program with functions that are needed from the C library.
receive program.
The program must be entered into a file. File name can consist of letters, digits and
program.c
The file is created with the help of text editor, either ed or vi.
COMPILNG THE PROGRAM
Let us assume that the source program has been created in a file named hello.c. Now
the program is ready for compilation.
The compilation command to achieve this under UNIX is
cc hello.c
EXECUTING A PROGRAM
Execution is a simple task. The command
a. out
would load the executable object code into memory and execute the instructions.
MULTIPLE SOURCE FILE
To compile and link multiple source program files, we must append all the fule names to the
cc command
cc filename-1.c….filename-n.c
These files will be separately compiled into object files called
filename-i.o