Friday 5 July 2013

C Basic Programming | C Programming Tutorial pdf

                      C – Basic Program

We are going to learn a simple “Hello World” program in this section. Functions, syntax and the basics of a C program are explained in below table.

Output:
Hello World!
Let us see the performance of above program line by line.

Compile and execute C program:
Compilation is the process of converting a C program which is user readable code into machine readable code which is 0′s and 1′s.
This compilation process is done by a compiler which is an inbuilt program in C.
As a result of compilation, we get another file called executable file. This is also called as binary file.
This binary file is executed to get the output of the program based on the logic written into it.
Steps to compile & execute a C program:
Step1 Type the above C basic program in a text editor and save as “sample.c”.
Step2 To compile this program, open the command prompt and goto the directory where you have saved this program and type “cc sample.c” or “gcc sample.c”.
Step3 If there is no error in above program, executable file will be generated in the name of “a.out”.
Step4 To run this executable file, type “./a.out” in command prompt.
Step5 You will see the output as shown in the above basic program.
C basic structure:

As already mentioned,c basic structure is defined by set of rules called protocol, to be followed by programmer while writing C program. Below is the C basic structure.

c basic structure in an example program:


Output:
This is main function
Total = 2
Let us see about each section of a C basic program in detail below. All below sections together are called as C basic structure.

Structure of C in real time application programs:
We have given simple real time application programs where the structure of a complete C program is shown. You can refer below C programs to know how to use C basics in real time programs.

Real time application C programs for your reference:

1.       C program example – Real time Calculator program

2.       C program example – Real time Bank Application program

Key points to remember:

  • Execution of every C program starts from main() function.
  • Protocol is set of rules to be followed by a programmer to write a program.                                                                                                            


No comments:

Post a Comment