First Program in C

Consider the following program written in C language:

	/*.....printing begins....*/
	printf("Hello,\nI am there.");
	/*.....printing ends......*/

The program when executed gives the following output:

I am there.

Now, let us have a look at the program. The first line of the program informs the sytem that program is main and the execution begins at this line. The main( ) is a special function used by C to indicate the start of program. Every program must have exactly one main function.
The opening brace “{” indicates the opening of the function main and the closing brace “}” indicates the closing of the function. The part inside the braces is known as the body of the program which contains statement which contains code to be executed. The end of statement is marked by a semi-colon “;” .

Any thing written between “ /*” and “*/” is ignored by the C-compiler and is known as comment. Comments do not affect the speed and size of the program. This is used by programmers to increase the readability of the program. It is helpful in debugging and testing.

The printf() function is a pre-defined standard C function which prints everything passed within the double quotes ” ” as shown below:

printf("Hello,\n I am there.");

It is to be noted that “\n” is a special character in C which informs the compiler to go the next line. It works on the concept of carriage return key on the keyboard. So in this case the message written after this is printed in a new line and so the output.

I am there.

The printf() function is pre-defined in stdio.h header therefore in order to use the functions such as printf and scanf we must declare it by including the following line in the program at the beginning otherwise a warning is generated at the compile time.


We should also take care that by default main function returns integer value. So “return 0;” statement should be added in the program or use void keyword which tells the compiler that program returns no value.


Author: Hifzur

I am a linux, programming and robotics enthusiast. I also love to write blog about life.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s