Hello world program in C

Print Hello World in C

Hello world is a classic program that is often used as an introductory program for beginners learning a new programming language. In this article, we will go through the steps to write and print “Hello, world!” in the C programming language.

First, let’s discuss what C programming language is. C is a general-purpose programming language that was developed in the early 1970s by Dennis Ritchie at Bell Labs. It is a low-level language that provides constructs that map efficiently to machine instructions, making it a popular choice for system-level programming.

Now, let’s write the program to print “Hello, world!” in C.

Step 1: Setting up the development environment
To write and run a C program, we need a text editor and a compiler. A compiler is a program that translates the human-readable code we write into machine-readable code that the computer can understand and execute. There are several C compilers available, including GCC, Clang, and Microsoft Visual C++. For this tutorial, we will be using the GCC compiler.

Step 2: Writing the code
Open a text editor and type the following code:

#include <stdio.h>

int main() {
printf(“Hello, world!\n”);
return 0;
}

Let’s go through this code line by line.

The first line #include <stdio.h> is a preprocessor directive that tells the compiler to include the standard input/output library, which provides functions for reading and writing data to and from the console.

The next line int main() { defines the main function of the program. In C, the main function is the entry point of the program and is where the program execution begins.

Inside the main function, we have the printf function, which is used to print output to the console. In this case, we are printing the string “Hello, world!\n”. The \n character is a newline character that adds a new line after the string is printed.

Finally, we have the return 0; statement, which indicates that the program has executed successfully and returns a value of 0.

Step 3: Compiling and running the program
Save the file with a .c extension, for example, helloworld.c. Open the terminal or command prompt and navigate to the directory where you saved the file. Run the following command to compile the program:

gcc helloworld.c -o helloworld

This command tells the GCC compiler to compile the helloworld.c file and generate an executable file called helloworld.

Now, run the program by executing the following command:

./helloworld

This command runs the helloworld executable file, and you should see “Hello, world!” printed on the console.

Congratulations! You have successfully written and run your first C program that prints “Hello, world!”.

In conclusion, C is a powerful programming language that is widely used in system-level programming. The “Hello, world!” program is a simple but effective way to get started with C programming. With this tutorial, you should have a basic understanding of how to write and run a C program.