# include <stdio.h> – This command is a preprocessor directive in C that includes all standard input-output files before compiling any C program so as to make use of all those functions in our C program.
int main() – This is the line from where the execution of the program starts. The main() function starts the execution of any C program.
{ (Opening bracket) – This indicates the beginning of any function in the program (Here it indicates the beginning of the main function).
/* some comments */ – Whatever is inside /*——-*/ are not compiled and executed; they are only written for user understanding or for making the program interactive by inserting a comment line. These are known as multiline comments. Single line comments are represented with the help of 2 forward slashes “//——”.
printf(“Hello World”) –The printf() command is included in the C stdio.h library, which helps to display the message on the output screen.
getch() – This command helps to hold the screen.
return 0 –This command terminates the C program and returns a null value, that is, 0.
} (Closing brackets)- This indicates the end of the function. (Here it indicates the end of the main function)
The components of the basic structure of a C program consists of 7 parts
- Document section
- Preprocessor/link Section
- Definition section
- Global declaration section
- Function declaration section
- Main function
- User-defined function section
1. Documentation Section
It is the section in which you can give comments to make the program more interactive. The compiler won’t compile this and hence this portion would not be displayed on the output screen.
2. Preprocessor directives Section
This section involves the use of header files that are to include necessarily program.
3. Definition section
This section involves the variable definition and declaration in C.
4. Global declaration Section
This section is used to define the global variables to be used in the programs that means you can use these variables throughout the program.
5. Function prototype declaration section
This section gives the information about a function that includes, the data type or the return type, the parameters passed or the arguments.
6. Main function
It is the major section from where the execution of the program begins. The main section involves the declaration and executable section.
7. User-defined function section
When you want to define your function that fulfills a particular requirement, you can define them in this section.
Compile and Execute C Program
Let us see how to save the source code in a file, and how to compile and run it. Following are the simple steps −
- Open a text editor and add the above-mentioned code.
- Save the file as c
- Open a command prompt and go to the directory where you have saved the file.
- Type gcc hello.cand press enter to compile your code.
- If there are no errors in your code, the command prompt will take you to the next line and would generate outexecutable file.
- Now, type outto execute your program.
- You will see the output "Hello World"printed on the screen.