C “Hello, World!” Program | First Program in C

Hello World in C | First Program In C Language | Tech-Mirror
Hello World in C | First Program In C Language | Tech-Mirror

Hello World in C

Let’s start C Language with very basic program Hello World in C. In Which we print “Hello World” on screen or console.

After talking about the history and compilers it is time to make code with c language.

We like to make C programs under Linux, so we will use a text editor and the gnu compiler. Remember, the examples included in the C is all console programs. That means they use text to communicate. All compilers support the compilation of console programs. Check How to Compile & Run C program

So Let’s Start with a Hello World in C.

Now save the program with .c extension.

#include<stdio.h>

With this line of code we include a header file called stdio.h. (Standard Input/Output header file). This file lets us use certain commands for input or output which we can use in our program. For instance it has commands for input like reading from the keyboard and output commands like printing things on the screen.

int main()

The int is what is called the return value (type of integer). Every program must have a main function where entry point of every program. It is also called that the starting point of every program.

{}

The two curly brackets, one in the beginning and one at the end are used to group all commands together. In this case all the commands between the two curly brackets belongs to main(). The curly brackets are often used in the C language to group commands together.

printf(“Hello World\n”);

The printf is used for printing any thing on the screen, in this case the string of : Hello World. As you can see the data that is to be printed is put inside round brackets. The words Hello World are inside inverted commas, because they are what is called a string. (A single letter is called a character and a series of characters is called a string). Strings must always be put between inverted commas. The \n is called an escape sequence. In this case it represents a newline character. After printing something to the screen you usually want to print something on the next line. If there is no \n then a next printf command will print the string on the same line.

return 0;

When we wrote the first line “int main()”, we declared that main must return an integer. (int is short for integer). With the command return 0; we can return the value null to the operating system. When you return with a zero you tell the operating system that there were no errors while running the program.


Output :

For More C Data Types

Leave a Reply

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