Sample C Program to Print Hello World

How to write a sample C program to print Hello World? It is the first program to start any programming language. The “Hello World” program helps to understand the basic programming structure of C Programming. So let see how we can write print Hello World using C language.

 

#include <stdio.h> 

int main()
{
    printf("Hello World\n");

    return 0;
}

Output:

Hello World

 

Explanation:

You can see the within the program to print hello world, I have included the “stdio.h“. The “stdio.h” is a standard input-output header file. This file allows you to use standard functions such as printf and scant. If you will not add this header file then we will get a warning. In the mentioned C program, I am using the print function to print my message on the console.

 

Watch this video to see how to print hello world using the printf function in C programming.

 

As we know there are a lot of formats specifies available in C programming. So if you want you can also print the “Hello World” C program using the character variable.

You can also see this article, C format specifiers.

#include <stdio.h>

int main()
{
  char a = 'H', b = 'e', c = 'l', d = 'o';
  char e = 'W', f = 'r', g = 'd';

  printf("%c%c%c%c%c %c%c%c%c%c\n", a, b, c, c, d, e, d, f, c, g);

  return 0;
}

Output:

Hello World

 

 

Recommended Post for you:

Leave a Reply

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