C is a powerful general-purpose programming language. It is fast, portable and available in all platforms. If you are new to programming, C is a good choice to start your programming journey.
This is a simple program in C programming language that prints “Hello, World!”.
#include <stdio.h>
int main() {
// printf() displays the string inside quotation
printf("Hello, World!");
return 0;
}
Breakdown of the Program
Let’s break down the code to understand how it works:
#include <stdio.h>: This is a pre processor command that includes standard input output library stdio.h.
int main(): This is the main function where the program execution begins.
{}: Curly braces define the body of the function.
printf("Hello, World!"): printf function is used to print the “Hello, World!” string on the screen.
return 0;: This is the “Exit status” of the program. In simple terms, the program ends with this statement.
How to Run the Program
- Open a text editor and add the above-mentioned code.
- Save the file as HelloWorld.c.
- Open a terminal and go to the directory where you saved the file.
- Type gcc HelloWorld.c and press enter to compile your code.
- If there are no errors in your code, the command prompt will take you to the next line and would generate a.out executable file.
- Now, type ./a.out to run your program.
- You will see “Hello, World!” printed on the screen.
Congratulations! You’ve just created and executed your first C program.
I hope this blog post helps you understand how to print “Hello, World!” in C programming language. Happy coding! 🎉
0 Comments