Basic Syntax
C Program Structure
Let's look at the most basic C program :
--------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------
When the program is run, it prints the following output :
Hello World!
Comments
Comments are a way of explaining what your program does. They are enclosed within /* */ and are not considered for compilation and execution. Comments are ignored by the compiler and are just a means for you and others to understand the piece of code.
< stdio.h > Header File
#include is a preprocessor directive which tells preprocessor to include the contents of stdio.h header file before compilation. stdio.h contains code that tells compiler what printf ( ) function will do and ofcourse it contains code for other standard library functions. There are many other header files which we should be included as and when required. Every header file consists of a set of functions which we can use to perform different tasks.
main ( )
The program execution begins at the main ( ) function. int (integer) specifies the return type of main ( ) funtion. Every program must have one and only one main ( ) function.
printf ( ) function
printf causes the message " Hello World " to be printed on the screen. printf ( ) is a standard library function. You will learn about other functions as you move along.
Return Type of main ( )
main ( ) returns an integer type value. The statement return 0; causes termination of the main ( ) function or the program and returns 0 ( integer ) to the Operating System.
Comments are a way of explaining what your program does. They are enclosed within /* */ and are not considered for compilation and execution. Comments are ignored by the compiler and are just a means for you and others to understand the piece of code.
< stdio.h > Header File
#include is a preprocessor directive which tells preprocessor to include the contents of stdio.h header file before compilation. stdio.h contains code that tells compiler what printf ( ) function will do and ofcourse it contains code for other standard library functions. There are many other header files which we should be included as and when required. Every header file consists of a set of functions which we can use to perform different tasks.
main ( )
The program execution begins at the main ( ) function. int (integer) specifies the return type of main ( ) funtion. Every program must have one and only one main ( ) function.
printf ( ) function
printf causes the message " Hello World " to be printed on the screen. printf ( ) is a standard library function. You will learn about other functions as you move along.
Return Type of main ( )
main ( ) returns an integer type value. The statement return 0; causes termination of the main ( ) function or the program and returns 0 ( integer ) to the Operating System.
No comments:
Post a Comment