Hello World C program - CodeMub

The "Hello World" program is the simplest program in computer programming. It is used to demonstrate the basic syntax of a programming language. In this blog, we will explore how to write a "Hello World" program in the C programming language.

C is a high-level programming language that is widely used for system programming and embedded systems. It was developed in the 1970s by Dennis Ritchie at Bell Labs. C is a procedural programming language that is known for its efficiency, portability, and flexibility. It is widely used for developing operating systems, compilers, and other system software.


Now, let's get started with the "Hello World" program in C.

Step 1: Install a C compiler


Before we start writing our "Hello World" program, we need to install a C compiler. A C compiler is a program that converts the source code written in C into machine code that can be executed by a computer.

There are several C compilers available, such as GCC, Clang, and Visual C++. We can choose any of these compilers depending on our operating system and personal preferences.

Step 2: Open a text editor

Once we have installed a C compiler, we need to open a text editor to write our "Hello World" program. A text editor is a program that allows us to create and edit plain text files.

There are several text editors available, such as Notepad, Sublime Text, and Visual Studio Code. We can choose any of these text editors depending on our personal preferences.

Step 3: Write the "Hello World" program

Now, we can start writing our "Hello World" program. Open a new file in the text editor and type the following code:


#include <stdio.h>

int main() {
   printf("Hello, World!");
   return 0;
}

The first line of the code #include is a preprocessor directive that tells the compiler to include the standard input-output library, which contains the printf function.

The main function is the entry point of the program. It is called when the program is executed. The printf function is used to print the string "Hello, World!" on the screen.

The return 0; statement is used to indicate that the program has executed successfully.

Step 4: Save the file

Once we have written the "Hello World" program, we need to save the file with a .c extension. We can choose any filename, but it is a convention to name the file the same as the main function.

Step 5: Compile the program

Now, we need to compile the "Hello World" program. Open a command prompt or terminal and navigate to the directory where the .c file is saved. Then, type the following

gcc helloworld.c -o helloworld
The gcc command is used to invoke the compiler. The -o option is used to specify the output file name. In this case, the output file name is helloworld. Step 6: Execute the program Once the program is compiled successfully, we can execute it by typing the following command in the command prompt or terminal:
./helloworld

Output

Hello, World!

This will run the program and print the string "Hello, World!" on the screen.

Conclusion

In this blog, we have learned how to write a "Hello World" program in the C programming language. We have also learned how to compile and execute the program. The "Hello World" program is just the beginning of our journey in C programming. We can use the concepts learned in this program to write more complex programs.

Next Post
No Comment
Add Comment
comment url