Hello World Program in C:
The Hello World program in C is a classic introduction to programming! It’s a simple program that displays the message “Hello, World!” on the screen. Here’s the code:
#include <stdio.h>
int main() {
printf("Hello, World!\n");
return 0;
}
Explanation:
Include Header File:
- #include <stdio.h> : This line includes the standard input-output library in C, which provides functions like printf() and scanf().
Main Function (int main()):
- Every C program must have a main() function, which serves as the entry point of the program.
- int before main() indicates that the function returns an integer value (usually 0 indicates successful execution).
Printing “Hello, World!”:
- printf(“Hello, World!\n”); : This statement prints the text “Hello, World!” to the console.
- \n is the escape sequence for a newline, which moves the cursor to the beginning of the next line after printing “Hello, World!”.
Return Statement:
- return 0; : This statement terminates the main() function and returns an integer value (0 in this case) to the operating system. It indicates that the program has ended successfully.
Algorithm:
Algorithm: Hello World Program in C
1. Start
2. Include the standard input-output library (stdio.h)
3. Define the main function:
a. Begin
b. Print "Hello, World!" to the console using printf()
c. Return 0 to indicate successful execution
4. End
Explanation of the Algorithm:
Step 1: The program begins execution.
Step 2: The program includes the necessary header file to use the printf() function.
Step 3:
- Substep a: The main function is defined as the entry point of the program.
- Substep b: It prints “Hello, World!” to the console using the printf() function.
- Substep c: It returns 0 to indicate to the operating system that the program has been executed successfully.
Step 4: The program ends.
Summary
The “Hello World” program in C is a simple demonstration of basic syntax and structure:
Purpose: Outputs “Hello, World!” to the console.
Key Components:
- Uses #include for input-output operations.
- Defines main() function as the program entry point.
- Calls printf() to print “Hello, World!” followed by a newline (\n).
- Returns 0 to indicate successful execution to the operating system.
Algorithm Summary:
- Includes the necessary library.
- Defines main() function.
- Prints “Hello, World!” using printf().
- Returns 0 to signify successful completion.
Discover more from lounge coder
Subscribe to get the latest posts sent to your email.