A typical C program basically consists of the following parts −
- Preprocessor Commands: In C programming language, preprocessor directive is a step performed
before the actual source code compilation. It is not the part of
compilation. Preprocessor directives in C programming language are used
to define and replace tokens in the text and also used to insert the
contents of other files into the source file. When we try to compile a program, preprocessor commands are executed first and then the program gets compiled. Every preprocessor command begins with # symbol.(Read More with Example)
- Functions
- Variables
- Statements & Expressions
- Comments
Lets see an example, Following is a basic C program to display "Hello,World!"
#include <stdio.h>
int main() {
/* my first program in C */
printf("Hello, World! \n");
return 0;
}
The above program can be understood by observing each statement one by one.
- 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.
- The next line int main() is the main function where the program execution begins.
- 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.
- The next line printf(...) is another function available in C which causes the message "Hello, World!" to be displayed on the screen.
- The next line return 0; terminates the main() function and returns the value 0.