Basic Syntax of C language || Basic Structure || Simple Program || Tutorial 04

 

Hello world C Program


#include <stdio.h>
int main()
{
    printf("Hello World!!");
    return ;
}


What is <stdio.h> ?

stdio.h is a header file which has the necessary information to include the input/output related functions in our program. Example printf, scanf etc.

If we use #include<stdio.h> in your c program, it will include stdio.h file into our source program which has the information for all input, output-related functions.


Why #include ?

#include is a preprocessor directory.

It will include the file which is given within the angle brackets "<>" into the current source file.

Why main()?

the main function is the starting point of program execution.

The operating system (OS) initiates the program execution by invoking the main function.

And it will expect an integer value from the main function. That integer value represents the status of the program. That's why we declared main function return type as int.

all the functions are calling here because the compiler runs this function only.

printf("Hello World");


printf is a function which is defined in stdio.h header file. It will print everything to the screen which is given inside the double-quotes.

In this case, Hello World will be printed as an output.

the semicolon ";" it’s a terminator in c 

Every statement in C should end with semicolon;.

Return 0;

As we declared main function return type as an integer, the calling function (operating system) will expect an integer value from the main function. In main function, we always explicitly return 0.

Program execution will reach return 0 statement if and only if all the above statements are executed without any error. If program execution reaches return 0 statement, We can ensure that there is no error in our program.

If some error occurred while program execution, the main function will return some non-zero value to the operating system to indicate the error.


0 Comments