All C programs have two main parts.
1.Header
2.Main
Header
Every standard header file contains a lot of inbuild functions. This header file ends with the extension .h.
Ex:
stdio.h
stdio.h contains all functions related to input and output. printf(), scanf() functions are in this header file called stdio.h.
A message can be displayed to the user from a C program using the printf() function.
We can get an input from the user by using scanf() function. So if we want to use this printf() and scanf() function in our program, we need to include this stdio.h header file.
Main Section:
The main section is the starting point of the program. When we run the program after writing it, the operating system first goes to the main function and starts executing from there. Each statement is executed there. Together these two parts give us a complete c programming.
#include<stdio.h>
int main()
{
printf(“Hello World”);
return 0;
}
#include<stdio.h>
#include is a preprocessor directory. Its job is to include the file given inside the angel bracket (<>) in the source file. In this program we have given a file called stdio.h.
The extension of stdio.h is the Standard Input Output Header File. It contains printf() and scanf() functions. printf() displays a message to the user and scanf() is used to receive input from the user. These functions If we want to use it in our program, we have to include the header file named stdio.h. The header file that we have included will be included in the current source file that we are writing in the preprocessor directory called #include.
int main()
When we run the program, the execution starts from the main function of the Operating System. Here int means that the main function will return an integer value. That integer value is called the program status. If the integer value is zero, any programming The operating system will know that there is no error and it is working fine. This means that if any number other than zero comes, the operating system will know that there is an error in the programming.
{ (open curly braces)
c programming is called block structured programming language. The open curly braces({) indicates the beginning of the block. The open curly braces({) given here indicates the beginning of the main function.
printf(“Hello World”);
A message can be sent to the user using the printf() function. When this program is executed, the hello world in printf() will be displayed to the user.
Printf() function must be given a semicolon(;) at the end, otherwise an error will be displayed in your program, because in C program, all statements are completed with a semicolon.
return 0;
We have already seen about this. That is, the main() function sends the programming status to the operating system. If the program status value is zero, it means success, and if it is non-zero, it means error. That is, all the statements from the main function are executed and finally return 0; comes to the statement. So return 0; If it comes to the statement, it will return zero and terminate the program.
If any error occurs in between, it will return a non-zero value and terminate the programming.
Whenever the program returns 0; When it comes to the statement, it means that there is no error in programming.
} (close curly braces)
We started from the main function using open curly braces({). All the necessary work in the main function has been completed. Now we put close curly braces(}) which means that the main function ends.