🧭 Navigation
⬅️ Previous | 🏠 Home | ➡️ Next
Let's start with the classic "Hello, World!" program. This is the traditional first program that every programmer writes when learning a new language.
#include <stdio.h> // Preprocessor directive: includes standard input/output library
int main(){ // Main function - program entry point
printf("Hello, World!"); // Print "Hello, World!" to the console
return 0; // Return 0 to indicate successful completion
}- What it does: Includes the standard input/output library
- Why needed: Gives us access to functions like
printf() stdio.h: Stands for "Standard Input Output Header"
- What it is: The main function - where program execution begins
int: Return type (integer)main: Function name (must be exactly "main")(): Empty parentheses mean no parameters
- What it does: Displays text on the screen
printf: Function to print formatted output"Hello, World!": The text to display (string literal);: Semicolon marks the end of the statement
- What it does: Ends the program and returns a value to the operating system
0: Indicates successful completion- Why 0: Convention - 0 means success, non-zero means error
Every C program follows this basic structure:
#include <header_files> // Include necessary libraries
int main() { // Main function (entry point)
// Your code here // Program statements
return 0; // End program
}Save the code in a file named basic_structure.c
gcc basic_structure.c -o basic_structure./basic_structureHello, World!
- Always end statements with semicolons (
;) - Missing semicolons cause compilation errors
- C is case-sensitive:
printf≠Printf≠PRINTF - Use exact spelling as shown
- Every opening brace
{must have a closing brace} - Braces define the scope of functions and blocks
//for single-line comments/* */for multi-line comments- Comments help explain your code
- Basic C program structure
- How to include libraries
- Main function syntax
- Using printf() function
- Proper program termination
Try modifying the program to print your name instead of "Hello, World!":
#include <stdio.h>
int main() {
printf("Hello, [Your Name]!\n"); // Replace [Your Name] with your actual name
return 0;
}Now that you understand the basic structure, you're ready to learn about:
- Tokens - The building blocks of C programs
- Variables - Storing and manipulating data
- Data types - Different kinds of information
🧭 Navigation
⬅️ Previous | 🏠 Home | ➡️ Next