C BASIC COMMANDS
BY ARUP MEDHI
A simple C program: -
# include <stdio.h>
int main()
{
/* My first C program */
printf(“Hello world!”);
getch();
return 0;
}
C basic commands Explanation
#include<stdio.h> This is a preprocessor command that
includes standard input output header
file (stdio.h) from the C library before
compiling a C program.
int main() This is the main function from where
execution of any C program begins.
{ This indicates the beginning of the main
function.
C basic commands Explanation
/*some comments*/ whatever is given inside the
comments “/* */ ” in any C
program, won’t be considered
for compilation and execution.
printf(“Hello World”) printf() function prints the
output onto the screen.
C basic Explanation
commands
getch(); This command waits for any character
input from keyboard. It is a predefined
function in “conio.h”.
return 0; This command terminates C
program(main function) and return 0
} This indicates the end of the main
function.
Comments/remarks
A comment is an explanation or description of the
source code of the program. Whatever is given as
comments in any C program, won’t be considered for
compilation and execution.
There are two ways to give comments in a c program
1. using // ( Single line comment )
e.g. // calculating the average temperature
// from among the 10 numbers
2. using /*…...*/ (Can be split over more than one
line)
e.g. /* here we are calculating the highest number
from among the 10 numbers */
What is an IDE (Integrated Development
Environment)?
An IDE is a special type of software which helps in
writing, editing, compiling and executing the
program of a particular programming language.
Some IDE’s have the capability of supporting
many programming languages.
Following are some of the popular IDE’s
for ‘C’ language-
Dev C++ Netbeans Code:: Block
Eclipse Code Lite C++
Builder
Turbo C++
/* Program to find the sum of two numbers */
#include<stdio.h>
#include<conio.h>
int main()
{
int a,b,c;
clrscr();
printf("\n\n Enter any two numbers:-");
scanf("%d%d",&a,&b);
c=a+b;
printf("\n\n The sum of the two numbers is:-%d",c);
getch();
return 0;
}
Life Cycle of a C Program
The program which is written by a programmer
himself is called a source code, this source
code is sent to a special kind of software which
is called a pre-processor. The task of the pre-
processor is to add some library functions to
the current content of your source code and
you end up getting expanded code. Now this
expanded code is sent to a special kind of
software which is called a compiler. The task of
the compiler is to go for compilation.
This is the process in which your expanded
code is converted into the machine language.
Once your program is converted into the
machine language it is termed as an object
code. The object code is sent to a special kind
of software which is called a linker. Through
linking what this linker does is it will prepare
an executable file. This executable file is the
final file which is created in this life cycle and
this file executes the whole program.