“From today on, study hard and make progress every day”
Repetition is the best method for memory; spend one minute every day to remember the basics of C language.

Learning C Language from Scratch in 2025: How to Write Your First Executable Program?
A One-Minute Quick Start Guide!
π Introduction: Why Does Your First C Program Always Fail to Run?Are you just learning C language, typing the code from the book, only to find compilation errors, crashes, or even a black window flashing by? Donβt panic! This article will guide you step by step to write your first truly executable C program and explain the meaning of each line of code, helping you thoroughly understand the underlying principles.
π Step 1: Set Up the C Language Development Environment
1. Choose a Compiler (So Your Computer Understands C Language)
C language requires a compiler to convert the code into a machine-executable program. Recommended:
- β’ Windows: MinGW (Download from official site) or Dev-C++ (suitable for beginners)
- β’ Mac/Linux: The system comes with GCC (check by entering
<span>gcc --version</span>in the terminal)
2. Install a Code Editor (Where You Write Code)
- β’ VS Code (recommended): Lightweight, rich in plugins (install C/C++ extension)
- β’ Clion: Professional C/C++ IDE (suitable for long-term learning)
π‘ Tip: If you donβt want to deal with the environment setup, you can use an online compiler (like OnlineGDB) to run the code directly.
βοΈ Step 2: Write Your First C Program
Open your editor, create a new file named <span>hello.c</span>, and enter the following code:
#include <stdio.h> // Include standard input-output library
int main() { // Main function, program execution starts here
printf("Hello, World!\n"); // Print Hello World!
return 0; // Return 0 indicates normal program termination
}
π Line-by-Line Analysis
- 1.
<span>#include <stdio.h></span>
- β’ Tells the compiler: “I want to use
<span>printf</span>and<span>scanf</span>, which are defined in the<span>stdio.h</span>header file.” - β’ Without this line,
<span>printf</span>will cause an error!
<span>int main()</span>- β’
<span>main</span>is the entry point of the program, like the “Start” button in a game; the operating system runs your code from here. - β’
<span>int</span>indicates that this function will eventually return an integer (usually<span>0</span>indicates success).
<span>printf("Hello, World!\n");</span>- β’
<span>printf</span>is the print function,<span>\n</span>represents a newline (otherwise the next output will be right next to it). - β’ Try removing
<span>\n</span>, and see what happens?
<span>return 0;</span>- β’ Tells the operating system: “Iβm done, everything is fine.”
- β’ If it returns
<span>1</span>or another value, it may indicate an error (like a file not found).
π§ Step 3: Compile and Run
Method 1: Command Line (Recommended, Understand the Underlying Layer)
- 1. Open the terminal (Windows is
<span>cmd</span>or<span>PowerShell</span>, Mac/Linux is<span>Terminal</span>). - 2. Navigate to the directory where your code is located (use the
<span>cd</span>command to change the path). - 3. Enter the compilation command:
gcc hello.c -o hello
- β’
<span>gcc</span>: Calls the compiler - β’
<span>hello.c</span>: Your source code file - β’
<span>-o hello</span>: The generated executable file is named<span>hello</span>(Windows will generate<span>hello.exe</span>)
./hello # Mac/Linux
hello.exe # Windows
β
If you see <span>Hello, World!</span>, congratulations! Your first C program is running!
Method 2: One-Click Run in IDE (For the Lazy)
- β’ In tools like VS Code, Dev-C++, just click the **”Run”** button (usually the βΆοΈ icon).
β Common Errors & Solutions
| Error Message | Possible Cause | Solution |
<span>'gcc' is not recognized as an internal or external command</span> |
GCC is not installed or environment variable is not configured | Reinstall MinGW and configure PATH |
<span>undefined reference to 'printf'</span> |
Did not include <span>#include <stdio.h></span> |
Check if the header file is missing |
| Black window flashes | The program closes immediately after running | Add <span>getchar();</span> before <span>return 0;</span> to pause |
π― Advanced Challenge: Make Your Program Smarter
Try modifying the code to make the program ask the user for their name and greet them:
#include <stdio.h>
int main() {
char name[20]; // Define a string variable to store the name
printf("Please enter your name:");
scanf("%s", name); // Read user input
printf("Hello, %s!\n", name); // Print personalized greeting
return 0;
}
π‘ Give it a try: What happens if the name you input contains spaces (like “Zhang San Li Si”)? Why? (Hint: <span>scanf</span> stops reading at spaces)
π Summary
β
Environment Setup: Install GCC + Code Editorβ
Code Structure: <span>#include</span>β<span>main()</span>β<span>printf</span>β<span>return 0</span>β
Compile and Run: <span>gcc hello.c -o hello</span>β<span>./hello</span>β
Debugging Tips: Check error messages, add <span>getchar()</span><span> to prevent flashing</span><span> </span>
π¬ Interactive Topic: Has your first C program run successfully? What problems did you encounter? Feel free to follow and leave a message for mutual learning! π
———- End ———-
[Special Statement: This public account article is original or authorized by the author, some content and images are sourced from the internet and AI, please feel free to consume, the views are for learning reference only~~]

“If you like C, please like it”
Click the bottom right corner to view
“