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

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

PST to PDF Converter to Export Outlook Data in Adobe PDF files

The increasing demand for Adobe Acrobat PDF files is also giving rise to queries like how to export Outlook PST file’s data in PDF format. This is because PDF is considered as a safe and portable document to store data. Outlook being widely used email application is widely used by home as well as corporate users. Saving emails and other components of PST file in PDF format simplifies the task of the user to open and access data on free platforms like Adobe Reader. They can be simply open on mobile devices without requiring any specific platform. PST to PDF converter tool is an excellent solution to export all PST file emails into PDF format along with embedded attachments. The tool will export all PST file emails in PDF format and create a separate PDF for each email. Users can export data even from corrupt PST file after properly scanning each item. Product Details And Activation Requirements Full Name of the Tool: PST to PDF Converter Current Version: 2.0 ...

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