Tuesday, September 15, 2015

First C Program




#include <stdio.h> 
#include <conio.h> 
void main()
{
            clrscr();
/* my first program in C */
            printf("Hello, World! \n"); 
            getch();
}

1.      The first line of the program #include <stdio.h> is a preprocessor command, which tells a C compiler to include stdio.h file before going to actual compilation.
2.      The second line of the program #include <conio.h> is a preprocessor command, which tells a C compiler to include conio.h file before going to actual compilation.
3.      The next line void main() is the main function where program execution begins. Void line tells the compiler that the main() function returns no values.
4.      clrscr() function is for clearing  the console.
5.      The next line /*...*/ will be ignored by the compiler and it has been put to add additional comments in the program. So such lines are called comments in the program.
6.      The next line printf(“Hello, World!\n”); is another function available in C which causes the message "Hello, World!" to be displayed on the screen. \n is for entering to a new line.
7.      The getch(); helps to read from keyboard. The function helps to keep the console displayed.


This will be theresult displayed in the console.


Hello, World!

No comments:

Post a Comment