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

End of Engineering and Begining of Web Raga

Finally my exams are over and here is the end of College Days. I don't know whether I will go for further studies or not, but surely I will try to do things out of the box.       We have started our work at e-Lightening Technologies and clients are just flowing to get their web presence. Definitely condition has been completely changed, two years back we used to convince each and every person coming to us why they should have a website for their business. But today people have agreed with this fact that if they want to be ahead of their competitors, they must have their online presence.  As far as this website is concerned, I have many plans. Soon we are going to hire 3 more Tech Bloggers to write for us. We are also going to have a seperate office for this website. We are now open for Guest Blogging. If you want to write for this website, please contact us using the contact form available on contact us page . From 14th June 2012, we will be p...

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...

Google's this Doodle is just Awwwsome!!!!

In celebration of Robert Moog’s 78th birthday, Google has created an epic Google Doodle to honor founder of Moog Music , pioneer of electronic music , best known as the inventor of the Moog synthesizer .The Doodle presents an interactive Moog synthesizer . Users can adjust dials on the synthesizer, turn switches on and off and play sounds on the keyboard. They can also record and playback their creations. Don't miss playing this with your keyboard!!!! Google is also showing a regular link of Google+ to share whatever music you have created.