Monday, January 6, 2014

Hello World - First C Program

In learning programming Languages, every beginner needs to start at the basics. The hello world program contains the basic parts of a program and it's functions. Now, let's proceed with the code.

First, we need to include the libraries to be used. Libraries contain the standard formats or collection of implementations that will be used. 
For example, the library <stdio.h> contains the printf, scanf and other basic functions needed for the program to run.

Declaring libraries always start with a hashtag or sharp ( # )

#include<stdio.h>

Then, we write the main() function.  The main() function contains all the blocks of codes of the program. For convenience of having the screen cleared every time a new program is run, we have the clrscr(); function. It can be written inside the main() function. 

#include<stdio.h>
main()
{


}



Always remember to have the brackets to identify the scope of the main() function. When printing messages, characters, numbers and symbols, we use the printf(); function It is also used to print variables, functions and pointers. Always remember to put a semicolon ( ; ) after every function.

For printing or displaying the "Hello World!" message on the screen we write:


printf("Hello World!");


Note that the Message or string is placed inside two double quotes ( " " ).  And to end the program, we shall use the getch(); function so that the user screen won't after the program execution.

Complete code is:                                                    Output:

#include<stdio.h>
main()
{
clrscr();

printf("Hello World!");

getch();

}

No comments:

Post a Comment