Curriculum
Course: Complete C Programming Course
Login
Text lesson

Writting a First Hello World Program in C

In this lesson, you will learn

  • Hello World program in C
  • Examples

 

Let’s go through the first Hello World program in C, followed by a line-by-line explanation of each part of the program.


Hello World Program in C

#include<stdio.h>

int main() {
    printf("Hello, World!\n");
    return 0;
}

Output:

Hello, World


 

Explanation of Each Line


### 🔹 #include <stdio.h>

  • #include is a preprocessor directive.

  • <stdio.h> stands for Standard Input Output Header file.

  • This line tells the compiler to include the standard I/O library, which contains the definition of the printf() function used later.


### 🔹 int main()

  • main() is the starting point of every C program.

  • int means the function will return an integer to the operating system.

  • Every program must have one main() function, where execution begins.


### 🔹 {

  • This opening curly brace { indicates the beginning of the function body.

  • All the statements inside the function are enclosed in { }.


### 🔹 printf("Hello, World!\n");

  • printf is a standard output function that displays text on the screen.

  • "Hello, World!\n" is a string literal.

    • The text inside quotes is printed as is.

    • \n is an escape sequence that moves the cursor to a new line after printing.

  • The ; is used to end the statement (very important in C).


### 🔹 return 0;

  • This statement returns 0 from the main() function.

  • In C, returning 0 typically means that the program executed successfully.

  • It is passed back to the operating system.


### 🔹 }

  • This closing brace } indicates the end of the function body.


 

Summary Table

CodeMeaning
#include <stdio.h>Tells the compiler to include standard I/O library
int main()Entry point of the program; returns an integer
{ }Denotes the block of code in the function
printf("Hello, World!\n");Prints “Hello, World!” followed by a newline
return 0;Sends a success code to the OS after program ends

 

Examples

Program 1: Add Two Numbers

#include<stdio.h>

int main() {
    int a = 5, b = 7, sum;
    sum = a + b;
    printf("Sum = %d\n", sum);
    return 0;
}

 

Sum = 12


 

 

 


End of the lesson….enjoy learning.

 

 

Student Ratings and Reviews

 

 

 

There are no reviews yet. Be the first one to write one.

 

 

Submit a Review