Credits

Sunday, February 8, 2009

C Shouts "Hello World!"

To start your C program, load the C editor so you can write your codes. A simple program can be the one below. A body of a C program basically resembles below:

/*This is a comment line.
The lines colored red are simply comments and must be enclosed in a pair of slash and
asterisks*/

#include stdio.h /*the stdio.h must be enclosed in <>. This line calls the library that supports basic I/O command*/

/*this signals the beginning of your main program.
printf command is used to display an output on the screen
and getche() shall halt the program on the runtime mode waiting for you to hit the keyboard*/
main( )
{
printf("Hello World!");
getche();
}

Each command line must end with a semi-colon. C program is case sensitive. Thus, all reserve words should be written in smaller case and identifiers should be used the same way, they were declared.

In Bloodshed C++, this will look like this:

#include iostream /*the iostream must be enclosed in <>. */
main( )
{
cout<<"Hello World!"; cin.get(); }


Compile and run this code and on the screen, you shall see, "Hello World!"
Congratulations! You have just made your first program.

AddThis