Hello world Program in C

Introduction

“Hello World! C Program” can be easily written in c programming language using printf function which prints characters on to terminal. For using printf first we have to include stdio header file using #include preprocessor. Then we can call printf function passing “Hello World!” to print.

Before we begin our first C program, let us do remember the following rules which are applicable to all C programs.

  • Each instruction in a C program is written as a separate statement.
  • Blank spaces may be inserted between two words to improve the readability of the statement. However, no blank spaces are allowed within a variable, constant, or keyword.
  • All statements are written in small case letters.
  • Every C statement must end with a ;.

Example Hello World Program in c

// The first C program which prints the message onto the console.

#include <stdio.h>
int main()
{
  printf("Hello world \n");
  return 0;
} 

Code Explanation

  • In the first line, I have written a comment, which begins with //. comment lines are meant for programmers to help code better understandably. These comment lines are ignored by the compiler.
  • #include<stdio.h> includes the standard input/output library functions. It is a preprocessor directive. The preprocessor’s job is to replace text content that begins with the # symbol with the actual content. The header file with a .h extension is called a header file. Header files contain declarations of functions like printf, scanf, etc..
  • int main() The main() function is the entry point to every program in the c language. It begins with opening the curly brace({) and ends with closing the curly brace(}).
  • printf() This is the built-in library function used to print the data onto the console. This function is defined in stdio.h header file.
  • return 0 This statement, returns execution status to the operating system. It has two values. 0 for successful execution and 1 for unsuccessful execution.

Output

First c program as hello world output

Hello World Program Using Functions

#include<stdio.h>
void hello_world()
{
 printf("Hello World!");
}
int main(int argc,char* argv[])
{
 hello_world();
 return 0;
}

Output

Hello World Program using Functions output

How to Run c Program?

To know how to setup IDE for c/c++ read this article.

To run the C program know how to instal an IDE and set up development environment.

You can refer to the C programming development environment setup tutorial here.

There are two ways to run c program. They are

By menu

First click on compile menu then compile sub menu. This helps to find out errors if any in your code. Then click on run menu and run sub menu to run c program.

By shortcut

Press ctrl+f9 keys to directly compile and run the c program.

You will see the following output on your console.