Before we start the basic building blocks of the C programming language, we must know the Program Structure of C for the building of programs.
A C program basically consists of the following parts:
- Preprocessor Commands.
- Functions.
- Variables.
- Statement & Expressions.
- Comments.
Let see the basic structure below to print Hello World:
1 2 3 4 5 6 7 8 9 | #include <stdio.h> int main() { /* This is my First Program */ // First Program printf("Hello, World! \n"); return 0; } |
Now, let’s know the various parts of the above example:
#include <stdio.h>
is a preprocessor command, the first line of the program that adds the stdio.h file before the program compilations.- Next is
int main()
which is the main function where the program execution begins. -
/*...*/
or//
is a comment box that will not be executed by the compiler. printf(...)
is a function in C that displays the message “Hello, World!
” on the screen. The message needs to be under" "
.return 0;
in a program terminates themain()
function and returns the value 0.