Hello World Program in C

The first program that developers learn to create in an unfamiliar programming language is usually a "Hello, world!" program. It's just a basic program that prints "Hello, world!" to the console. The following article will demonstrate how to write a C program that states, "Hello, world!"

As we know, C is a general-purpose programming language which we use for embedded devices, system programming, and creating applications. It is a versatile programming language that provides low-level control over the hardware of the computer, making it an excellent option for creating operating systems and device drivers.

The first step to creating a "Hello, world!" program in C is creating and setting up a development environment. We need a text editor to write the code and a C compiler to compile and run the program. There are various popular C processors available, such as GCC, Clang, and Microsoft Visual C++. In this tutorial, we will use GCC, which is a free and open-source compiler available for Windows, Linux, and macOS.

Step 1: Install GCC

To install GCC on Linux, open a terminal and type the following command:

This will install the GCC compiler along with other essential tools for building software.

Use Homebrew, a well-liked programme manager for macOS, to install GCC. To launch the application, type this command into the terminal.:

This will install the GCC compiler on your system.

To install GCC on Windows, you can use the MinGW-w64 project, which provides a Windows port of the GNU Compiler Collection. You can also download the installer by following the link given here : https://sourceforge.net/projects/mingw-w64/

Step 2: Write the code

Open a text editor and create a new file called hello.c. This file will contain the C code for our "Hello, world!" program.

Type the following code into the file:

C Program:

Output

Hello, world!

Let's break down this code. The preprocessor directive in the first line, "#include<stdio.h>," instructs the compiler to include the standard input/output library. This library contains the "printf()" function, which we will use to print the message to the console.

The next line 'int main() {' is the main function of our program. The execution of the programme begins at this time. The word "int" before the word "main()" denotes that the function returns an integer number.

The next line 'printf("Hello, world!\n");' is the heart of our program. The command "printf()" is used to print "Hello, world!" to the console. The special character '\n' at the conclusion of the string stands for a newline, which causes the cursor to move to the next line after the message has been printed.

The final sentence, "return 0;" is used to end the programme and give the operating system a value of 0. This value represents an effective programme execution.

Step 3: Compile and run the program

Now that we have written the code, we can compile and run the program. Move to the location that contains hello.c file in a terminal.

Enter this command to begin the program:

This will invoke the GCC compiler and create an executable file called hello from the source file hello.c.

Enter this command to begin the program:

This will run the hello program and display "Hello, world!" on the screen.

Congratulations! You have successfully written and executed your first C program.

Conclusion:

In conclusion, a "Hello, world!" program in C is a simple yet essential program that helps developers learn the basics of the C programming language and set up their development environment.






Latest Courses