C Hello World Program

The fundamental framework of a straightforward C program commonly comprises various crucial elements. Here are some of the most frequently employed components within a C program:

1) Header Files:

Header files in C programming are usually added at the beginning of the program using the #include directives. These files are frequently utilized to provide the prototypes and definitions of functions, allowing the compiler to comprehend and interpret the functions utilized within the program.

2) Main Function:

The main function within a program is commonly known as the starting point of the program. It is designed to return an integer type as it must provide an integer value to the operating system upon execution completion.

3) Variable Declarations:

If there is a requirement to incorporate variables in the program, it is essential to define these variables along with their respective data types prior to their usage. This practice is frequently observed following the opening curly brace of the main function.

4) Statements and Expressions:

This section of the C code houses the program instructions and its underlying logic. C code comprises multiple instructions that execute tasks and evaluate expressions to determine values. These instructions can execute a variety of tasks, such as assignments, loops, and function calls.

5) Comments:

Comments play a crucial role in the C programming language, serving as descriptive annotations for human understanding of the code. These annotations have no effect on the program's functionality during compilation. Various forms of comments are present in C programming, such as Single-line comments indicated by // and multi-line comments enclosed within / /.

6) Functions:

User-defined functions, also referred to as code blocks, are crafted to carry out specific tasks within C programs. These functions play a crucial role in structuring the program, enhancing its organization, reusability, and maintainability.

7) Return Statement:

The return statement in C is also employed to conclude a function and send a value back to the calling function. A return statement containing 0 generally signifies successful completion. Conversely, a non-zero value signifies an error or unexpected termination.

8) Standard Input/Output:

The C program comprises numerous library functions, such as the scanf and printf functions. The scanf function is employed for accepting user input, while the printf function is utilized for displaying output on the console. These functions are integral to C programs and are part of the standard I/O library.

C Simple Hello World Example

Let's consider a scenario to showcase the basic Hello World program in the C programming language.

Example

Example

#include <stdio.h>  //header file



int main() {  //main function



    // print statement

    printf("Hello World!");



    return 0;  //return statement

}

Output:

Output

Hello World!

Explanation:

Here, we are going to examine this software sequentially.

  • #include <stdio.h>:

It represents the initial line of code, housing the standard input/output library (stdio.h). Within stdio.h, there are functions such as printf and scanf for input/output tasks.

  • int main { ... }:

It serves as the primary function of the software, commonly known as the starting point of the program. This phase marks the initiation of program execution.

  • printf("Greetings Earth!\n");

In the C programming language, the printf function is employed to showcase formatted information on the console. In this instance, the text "Hello World!" is exhibited, accompanied by the newline character (\n). The utilization of \n shifts the cursor to the subsequent line once the message is showcased.

  • return 0;:

It provides the output of the program. When the return statement is 0, the program has executed successfully. In case the return statement is any value other than zero, the execution is considered unsuccessful. Following compilation and running, the program concludes with a status code of 0 and outputs "Hello World!" to the console.

Steps by Step Process to Write the C Program

To compose, compile, and execute the initial C program, it is essential to adhere to the subsequent procedures:

Step 1: Open a text editor

Firstly, we need to launch a text editor that we prefer, like Notepad, Sublime Text, or Visual Studio Code. This tool will serve as the platform for composing our C code.

Step 2: Write the C program

Now, we need to input the subsequent code into the text editor:

Example

#include <stdio.h>  

int main() {  

printf("Hello, C Language");  

return 0;  

}

Step 3: Save the file

Afterward, save the document with a .c extension, like first_program.c. This specific extension denotes that the file contains C programming source code.

Step 4: Compile the program

Now, compile the program in the command prompt.

Step 5: Run the program

Upon completing the compilation process successfully, the program can be initiated by running the executable file that was created. Input the provided command in either the terminal or command prompt:

Example

./first_program

The software will run, and the result will be displayed on the console:

Output:

Output

Hello World!

How to Compile and Run the C program

There are two methods to compile and execute the C program: through the menu and using a shortcut.

1. By Menu

Now, select the compile option from the menu and then choose the compile sub-menu to compile the C program. Next, opt for the run menu followed by the corresponding sub-menu to execute the C program.

2. By shortcut

If we want to execute the program via a shortcut, press the Ctrl+F9 keys to compile and run the program directly.

  • We will see the following output on the user screen.
  • We can view the user screen at any time by pressing the Alt+F5 keys.
  • Now, press Esc to return to the Turbo C++ console.
  • Key Points to Remember in C Programming

There are several main points in the C programming. Some of them are as follows:

  • We need to always use a semicolon (;) at the end of a statement.
  • We have to use proper double quotes (" ") in the program's statement.
  • We need to use the printf function instead of using print or Print.
  • We also have to include <stdio.h> before using the printf function.
  • Conclusion:

In summary, the C program serves as a fundamental yet efficient initiation into the language, showcasing the essential program structure and execution flow. It highlights the fundamental elements essential for crafting functional programs, introducing the standard input-output library that designates the main function as the entry point, and employing the printf function to display output messages.

Input Required

This code uses input(). Please provide values below: