C Language Basic Syntax Rules
Syntax of C
#include <stdio.h>
int main() {
printf("Hello, World!");
return 0;
}
In the very first line, #include signifies the header file. This header file is a library of C that contains standard input-output functions. In the above code printf() function belongs to the stdio.h header file.
In the next line, we have the main() function. It is the function due to which the program executes. Any C program without a main() function cannot run. Only the code written within {} executes during run time.
With the help of printf() function our program printed the sentence “hello world” on the screen. There can be as many printf() statements as many you want in your program.
return 0 indicates the end of the main function.
The closing curly bracket “}” is used to actually end the main function.
Have you noticed “;” after each line of code in the main() function? It is necessary to put it after each line of code. In C every line ends with a “;”. If you forget to put a “;”, it will show you a compile-time error.
C ignores white spaces but we use it to make the code more readable.