C Language Environment Setup

Before learning data structures and algorithms, you need to set up a development environment that can smoothly compile and run C programs.

You can also refer to the installation and setup section in our C Language Tutorial:https://www.example.com/cprogramming/c-environment-setup.html


Compiler Installation

This tutorial recommends usingGCC(GNU Compiler Collection), which is a cross-platform, open-source C language compiler widely used in production environments.

Windows System

On Windows, it is recommended to useMinGW-w64orMSYS2to obtain the GCC compilation environment.

Installation steps:

  1. VisitMinGW-w64 official websiteDownload the installer
  2. Run the installer and select the architecture asx86_64, and choose the thread modelposix
  3. After installation, add the MinGW-w64bindirectory (e.g.,C:\mingw64\bin) to the system environment variable PATH
  4. Open Command Prompt (cmd) and entergcc --versionto verify whether the installation was successful
C:\Users\example> gcc --version
gcc (MinGW-W64 x86_64-posix-seh) 13.2.0
Copyright (C) 2023 Free Software Foundation, Inc.

macOS System

On macOS, installing Xcode Command Line Tools gives you GCC (actually a wrapper for Clang, compatible with GCC usage).

Open Terminal and run the following command:

$ xcode-select --install

The system will show an installation prompt; click "Install" and wait for it to complete.

After installation, verify that the compiler is available:

$ gcc --version
Apple clang version 16.0.0 (clang-1600.0.26.4)
Target: arm64-apple-darwin25.5.0
Thread model: posix

Linux System

Most Linux distributions can install GCC with one command through their package manager.

Ubuntu/Debian systems:

$ sudo apt update
$ sudo apt install gcc build-essential

Fedora/CentOS systems:

$ sudo dnf install gcc gcc-c++

Verify installation:

$ gcc --version
gcc (Ubuntu 13.2.0-4ubuntu3) 13.2.0

IDE Recommendations

The following are several C language integrated development environments suitable for beginners.

IDEPlatformFeaturesSuitable for
VS CodeCross-platformLightweight, rich plugin ecosystem, flexible configuration, used with C/C++ pluginLearners who like customizing configurations
Code::BlocksCross-platformDesigned specifically for C/C++, out-of-the-box, includes MinGW (Windows version)Beginners, those who don't want to deal with configuration
Dev-C++WindowsLong history, simple interface, install and useWindows beginners
CLionCross-platformMade by JetBrains, intelligent code completion, powerful debugging featuresThose with some foundation, seeking efficiency

The code examples in this tutorial do not depend on a specific IDE; any one of them can compile and run normally.

If you don't want to install any tools locally, you can also use an online compiler (such asCompiler Explorer、OnlineGDB) to quickly verify code.

For beginners, this tutorial recommends the combination of VS Code + MinGW-w64 (Windows) or VS Code + Xcode Command Line Tools (macOS), which is lightweight and fully functional.


First C Program

After setting up the environment, immediately write and run the classic "Hello, World!" program to confirm everything is configured correctly.

Create a new file namedhello.c, and enter the following code:

Example

#include <stdio.h> /* Standard input/output header file, provides printf function */

int main() {
    /* printf: function that outputs a string to the console \n: newline character, moves the cursor to the next line */
/* Return 0 indicates the program ended normally */

    printf("Hello, World! Welcome to EXAMPLE DSA Tutorial!\n");
    return 0;  Code structure explanation (from top to bottom):
}

Code section

DescriptionPreprocessor directive, includes the standard input/output library, allowing us to use the printf function
#include <stdio.h>The entry function of the program; every C program starts executing from the main function
int main()The entry function of the program; every C program starts executing from the main function.
printf(...)Formatted output function, prints the string in parentheses to the screen
return 0;Returns an exit code to the operating system, 0 indicates the program ended normally

After saving the file, use the following command in the terminal to compile and run:

# 编译:将 hello.c 编译为可执行文件 hello
$ gcc hello.c -o hello

# 运行,Windows 下为 hello.exe
$ ./hello
Hello, World! Welcome to EXAMPLE DSA Tutorial!

If the terminal correctly outputs the above text, it means your C language development environment has been configured successfully.


Detailed Explanation of Compilation Commands

The basic format of the GCC compilation command is:

gcc [选项] 源文件 -o 输出文件

Common compilation options:

OptionMeaningExample
-o <file>Specify the output file namegcc hello.c -o hello
-WallEnable all common warnings to help identify potential issuesgcc -Wall hello.c -o hello
-gGenerate debug information for use with debuggers such as GDBgcc -g hello.c -o hello
-std=c99Specify using the C99 standardgcc -std=c99 hello.c -o hello
-std=c11Specify using the C11 standardgcc -std=c11 hello.c -o hello
-O2Enable optimization (O2 level, balancing compilation time and runtime efficiency)gcc -O2 hello.c -o hello

This tutorial recommends the following compilation command for daily use:

$ gcc -Wall -g -std=c11 hello.c -o hello

This command enables warnings, generates debug information, and uses the C11 standard to compile your program.

Other extensions