- C Programming Tutorial
- C - Home
- Basics of C
- C - Introduction
- C - Features
- C - Basics
- C - History
- C - Structure of C Program
- C - Program Structure
- C - Hello World
- C - Compilation Process
- C - Comments
- C - Tokens
- C - Keywords
- C - Identifiers
- C - User Input
- C - Basic Syntax
- C - Data Types
- C - Variables
- C - Integer Promotions
- C - Type Conversion
- C - Type Casting
- C - Booleans
- Constants and Literals in C
- C - Constants
- C - Literals
- C - Escape sequences
- C - Format Specifiers
- Operators in C
- C - Operators
- C - Arithmetic Operators
- C - Relational Operators
- C - Logical Operators
- C - Bitwise Operators
- C - Assignment Operators
- C - Unary Operators
- C - Increment and Decrement Operators
- C - Ternary Operator
- C - sizeof Operator
- C - Operator Precedence
- C - Misc Operators
- Decision Making in C
- C - Decision Making
- C - if statement
- C - if...else statement
- C - nested if statements
- C - switch statement
- C - nested switch statements
- Loops in C
- C - Loops
- C - While loop
- C - For loop
- C - Do...while loop
- C - Nested loop
- C - Infinite loop
- C - Break Statement
- C - Continue Statement
- C - goto Statement
- Functions in C
- C - Functions
- C - Main Function
- C - Function call by Value
- C - Function call by reference
- C - Nested Functions
- C - Variadic Functions
- C - User-Defined Functions
- C - Callback Function
- C - Return Statement
- C - Recursion
- Scope Rules in C
- C - Scope Rules
- C - Static Variables
- C - Global Variables
- Arrays in C
- C - Arrays
- C - Properties of Array
- C - Multi-Dimensional Arrays
- C - Passing Arrays to Function
- C - Return Array from Function
- C - Variable Length Arrays
- Pointers in C
- C - Pointers
- C - Pointers and Arrays
- C - Applications of Pointers
- C - Pointer Arithmetics
- C - Array of Pointers
- C - Pointer to Pointer
- C - Passing Pointers to Functions
- C - Return Pointer from Functions
- C - Function Pointers
- C - Pointer to an Array
- C - Pointers to Structures
- C - Chain of Pointers
- C - Pointer vs Array
- C - Character Pointers and Functions
- C - NULL Pointer
- C - void Pointer
- C - Dangling Pointers
- C - Dereference Pointer
- C - Near, Far and Huge Pointers
- C - Initialization of Pointer Arrays
- C - Pointers vs. Multi-dimensional Arrays
- Strings in C
- C - Strings
- C - Array of Strings
- C - Special Characters
- C Structures and Unions
- C - Structures
- C - Structures and Functions
- C - Arrays of Structures
- C - Self-Referential Structures
- C - Lookup Tables
- C - Dot (.) Operator
- C - Enumeration (or enum)
- C - Structure Padding and Packing
- C - Nested Structures
- C - Anonymous Structure and Union
- C - Unions
- C - Bit Fields
- C - Typedef
- File Handling in C
- C - Input & Output
- C - File I/O (File Handling)
- C Preprocessors
- C - Preprocessors
- C - Pragmas
- C - Preprocessor Operators
- C - Macros
- C - Header Files
- Memory Management in C
- C - Memory Management
- C - Memory Address
- C - Storage Classes
- Miscellaneous Topics
- C - Error Handling
- C - Variable Arguments
- C - Command Execution
- C - Math Functions
- C - String Functions
- C - Static Keyword
- C - Random Number Generation
- C - Command Line Arguments
C Programming - C Hello World Program
![]() Share with a Friend |
C Programming - C Hello World Program
The "Hello, World!" program is the simplest C program that demonstrates the basic structure of a C program and outputs the text "Hello, World!" to the console. Below is the code, followed by a detailed explanation:
Code Example: Hello World in C
Example:
#include <stdio.h> // Preprocessor directive to include the standard input/output header int main() { printf("Hello, World! \n"); // Print "Hello, World!" to the console return 0; // Return 0 to indicate successful execution }
Explanation of the Code
- #include <stdio.h>
- This preprocessor directive includes the Standard Input/Output library.
- The library provides functions like printf() and scanf() that are used for input and output operations.
- int main()
- This is the main function, where the execution of the program begins.
- It returns an integer value to the operating system. A return value of 0 typically signifies successful execution.
- printf("Hello, World!\n");
- The printf() function is used to display the string "Hello, World!" on the console.
- The \n adds a newline after the output, moving the cursor to the next line.
- return 0;
- This statement indicates that the program has completed successfully.
- The integer value 0 is returned to the operating system.
Output
When you run the program, the output will be:
Hello World!
Steps to Run the Program
- Write the Code: Save the code in a file with the .c extension (e.g., hello_world.c).
- Compile the Program: Use a C compiler like gcc to compile the program:
gcc hello_world.c -o hello_world
- Run the Executable: Execute the compiled program:
bash
./hello_world
- View the Output: The message Hello, World! will be displayed on the console.
Key Points
- Portability: The program can be compiled and executed on various platforms.
- Basic Syntax: The example demonstrates the basic syntax and structure of a C program.
- First Program: It is often the first program written by beginners to get started with C programming.
This simple program is a foundational step toward understanding more complex concepts in C.
