Your First C Program
In previous two sections we have learnt how to setup c environment and steps in c program compilation. Now we are going to learn how to write a simple C program.
Type the following program into your favorite editor
//C simple program
/* It prints Hello World */
printf( "Hello, World\n");
Save it as hello.c, Compile and execute using following steps
Let us look at various parts of above c program
- The first line of program //C simple program is a single line comment. This line is ignored by compiler.
- The Next 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. its called as header file.
- The next line int main() is the main function where program execution begins and int is the return type of main function.
- The next /*It prints Hello World */ is a multi line comment.
- The next line printf(...) is another function available in C library which causes the message "Hello, World" to be displayed on the screen.
- The next line return 0; terminates main()function and returns the value 0.