Let's start C Programing by saluting the world! Type the following program into your favorite editor:
#include <>
void main()
{
printf("\nHello World\n");
}
We are using the free Borland C compiler because it is powerful, flexible, and allows us to create software for both command line and GUI (Windows) applications.
Of course, the first thing that you will need to do is download the Borland C compiler (explained in the Free Programming Tools article, and install it following the instructions received during the download process.
Before we continue, we should point out that only the C language tutorial part of this free C tutorial is valid for MacOS users, since it is targeted towards the free Borland C compiler available for Windows and Linux.
Download Compiler Here
Compile your First Program
Save your program in a suitable text file (HelloWorld.c - note the .c extension), and turn it into a command line application by:
- Open a Command Prompt
- Navigate to the place you saved your HelloWorld.c file
- Type 'bcc32 HelloWorld.c'
Every C program contains a function called main. This is the start point of the program.
#include
Allows the program to interact with the screen, keyboard and filesystem of your computer. You will find it at the beginning of almost every C program.
main()
Declares the start of the function, while the two curly brackets show the start and finish of the function. Curly brackets in C are used to group statements together as in a function, or in the body of a loop. Such a grouping is known as a compound statement or a block.
printf("This is a C program\n");
Try this out –
Example 1.
#include <>
void main()
{
printf("\n");
printf("Hello World");
printf("\n");
}
Example 2.
#include <>
void main()
{
printf("\nHello World\n");
}
No comments:
Post a Comment