Skip to main content

How to write a Basic C program

basic c program


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.





Popular posts from this blog

How to write a bach file or a batch job?

If your are connected with world of programming, you might have heard this word " Batch File ". A batch file is used to execute a no of operations or a list of commands one after the other often requiring no user input. A no of operations are batched in a file to be executed sequentially when we run that file. In Microsoft Windows Operating system a batch file is a file saved with .bat extension while in other operating systems like Unix and Linux it can be written as a command file shell script. Batch files are often used to load programs, run multiple processes at a time, and perform common or repetitive tasks. For example, a batch job could be used to back up many files on a computer system, process log files, run a series of calculation commands, run multiple system diagnostic processes, or any number of other things that require multiple commands to be run. A big advantage of a batch job is that it can be started at any time and left alone until t...

Adding Password to Microsoft Word Document

Recovering Deleted Files, Pictures & Videos

  So many times we accidently delete some important files, pictures or videos. Sometimes we loose files because of unexpected system failure  ( ultimately causing system format). We can get our deleted files back using Recovery Softwares/Utilities.  Even though a file was deleted there is a good chance that contents of the file are still around.  When a file is deleted the contents of the file are not removed. Only a pointer to the file in the file system table is deleted.   It is very important to immediately stop writing to the storage device that previously contained your files/pictures so that the old file contents are not overwritten.  For example, don’t take any more pictures with your digital camera because new pictures will overwrite the deleted files. HOW TO RECOVER DELETED FILES???? Step1: You will need to use a utility to recover your lost files. I like to use a free ut...