First of all you need to know about the language in conversation, yes I am talking about C language. C is a programming language used to write computer programs; whereas computer programs are finite sequence of instructions given to a computer to solve a particular task. In this post, I am going to share very basic knowledge about C programming. Without any further comments I would directly tell you the structure of a basic C program:
#include<stdio.h> //Preprocessor Directive
#include<conio.h> //Preprocessor Directive
void main()
{
int a, b, c; //Variable Declaration
printf("\n Enter any two numbers!!!");
scanf("%d%d",&a,&b);
c=a+b;
printf("\n\nSum = %d",c);
getch();
}
Explanation:
#include is the preprocessor directive, that directs your compiler to include file mentioned in the angular brackets. Here we have included two files stdio.h i.e. Standard Input Output Header file. and conio.h i.e. Console Input Output Header file. These are library files which have many functions defined in it. We can make use of those functions to create our programs.
void main()
main is a function. In any C program it is compulsory to write a main function. The execution of your program begins with main(). It is necessary for every function to return a value, when the function is not returning anything it will return void (nothing), that's the reason we have used void main().
"{..........}"
A pair of curly braces indicate a code block. Every function has set of instructions enclosed in the curly braces.
int a; is a c statement which declares a variable of name a as integer. Once you have declared the variable as integer you will be able to accept / assign a number to that variable.
printf() is a function used to display anything on the output screen.
scanf() is a function used to scan input from the keyboard.
getch() is a function used to accept a character without displaying anything on the screen.
