Your First Program in C

Writing the first program in any language is always exciting. Here we are going to write the famous “Hello World” Program in C. The program prints the message “Hello World” in the output.

Displaying “Hello World” in C

// "Hello World" Program in C
  
// Include the header file for the input/output
#include <stdio.h> 
  
// main function - 
// where the execution of program begins 
int main() 
{ 
  
    // print Hello World 
    printf("Hello World"); 
    Return 0;
 
}

Output

Hello World

C Program Elements Explained

Despite its simplicity, we will explain the elements of the program above, which are the basics of any C program.

#include <stdio.h>

#include is a directive; it tells the compiler to include the header file stdio.h, which is for the library that contains input and output function, such as the input scanf(), and the output printf().

int main()

This is the main program function. int is the return data type, and main() is its name. The program in C starts and ends with curly brackets { }

printf(“Hello World”);

printf is the function that displays anything you place within the double quote, which is “Hello World” in our case.

Return 0

Since the main() function return type is int, return 0 indicates that the program has successfully executed.

 

Back to: Learn C Programming > Overview of C

Leave a Reply

Your email address will not be published. Required fields are marked *