C Program to Print Hello World

Introduction

In programming, printing "Hello, World!" is often the first step for beginners to get familiar with the syntax of a programming language. This guide will show you how to write a simple C program to print "Hello, World!" to the console.

Problem Statement

Create a C program that:

  • Prints the text "Hello, World!" to the console.

Example:

  • Output: Hello, World!

Solution Steps

  1. Include the Standard Input-Output Library: Use #include <stdio.h> to include the standard input-output library, which is necessary for using the printf function.
  2. Write the Main Function: Define the main function, which is the entry point of every C program.
  3. Use printf to Print the Message: Call the printf function inside the main function to print "Hello, World!" to the console.

C Program

#include <stdio.h>

/**
 * C Program to Print "Hello, World!"
 * Author: https://www.javaguides.net/
 */
int main() {
    // Step 1: Print the message "Hello, World!"
    printf("Hello, World!\n");
    return 0;  // Step 2: Return 0 to indicate successful execution
}

Explanation

Step 1: Print the Message "Hello, World!"

  • The printf function is used to print the text "Hello, World!" to the console. The \n at the end of the string is a newline character, which moves the cursor to the next line after printing.

Step 2: Return 0

  • The return 0; statement indicates that the program executed successfully. In C, returning 0 from the main function is a standard way to signify that the program ran without errors.

Output Example

Example:

Hello, World!

Conclusion

This simple C program demonstrates how to print "Hello, World!" to the console. It’s an essential first step in learning C programming, allowing beginners to understand the basic structure of a C program, including the use of libraries, the main function, and the printf function.

Leave a Comment

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

Scroll to Top