Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

C Language Environment Setup

C Language Environment Setup

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

You can also refer to the installation and setup section of our C language tutorial:https://www.runoob.com/cprogramming/c-environment-setup.html


Compiler installation

This tutorial recommends GCC (GNU Compiler Collection), a cross-platform, open-source C compiler widely used in production.

Windows

On Windows, it is recommended to obtain the GCC build environment via MinGW-w64 or MSYS2.

Installation steps:

  1. Access the MinGW-w64 official website Download the installer
  2. Run the installer, choose the x86_64 architecture and the posix thread model
  3. After installation, add the MinGW-w64 bin directory (e.g. C:\mingw64\bin) to the system environment variable PATH
  4. Open the command prompt (cmd) and type gcc --version to verify the installation succeeded


C:\Users\runoob> gcc --version

gcc (MinGW-W64 x86_64-posix-seh) 13.2.0

Copyright (C) 2023 Free Software Foundation, Inc.

macOS

On macOS, install the Xcode command-line tools to get GCC (actually a wrapper around Clang, compatible with GCC usage).

Open a terminal and run the following commands:



$ xcode-select --install

The system will prompt for installation; click "Install" and wait for it to finish.

After installation, verify 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

Most Linux distributions can install GCC with a single command via the 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


Recommended IDEs

Here are several C-language integrated development environments suitable for beginners.

IDE Platform Feature Suitable for
VS Code Cross-platform Lightweight, rich plugin ecosystem, flexible configuration, used with the C/C++ plugin Learners who like custom configuration
Code::Blocks Cross-platform Designed specifically for C/C++, ready to use out of the box, includes MinGW (Windows version) Beginners who do not want to fuss with configuration
Dev-C++ Windows Long-standing, clean interface, install and use immediately Windows beginners
CLion Cross-platform From JetBrains, intelligent code completion, powerful debugging Users with some experience who pursue efficiency

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

If you do not want to install any tools locally, you can also use an online compiler (e.g. Compiler Explorer, OnlineGDB) to quickly verify your code.

For beginners, this tutorial recommends the combination of VS Code + MinGW-w64 (Windows) or VS Code + Xcode command-line tools (macOS): lightweight and fully featured.


Your 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 named hello.cand enter the following code:

Example

#include  /* standard input/output header, provides the printf function */

int

main

(

)

{

   

/* printf: a function that outputs a string to the console
       \n: newline character, moves the cursor to the next line */

   

printf

(

"Hello, World! Welcome to RUNOOB DSA Tutorial!\n"

)

;

   

return

0

;

 

/* returning 0 indicates the program ended normally */

}

Code structure explanation (top to bottom):

Code section Description
#include Preprocessing directive that includes the standard input/output library so we can use the printf function
int main() The program's entry function; every C program starts execution from the main function
printf(...) A formatted output function that prints the string in parentheses to the screen
return 0; Returns an exit code to the operating system; 0 means the program ended normally

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



# Compile: Compile hello.c into the executable file hello

$ gcc hello.c -o hello



# Run, hello.exe on Windows

$ ./hello

Hello, World! Welcome to RUNOOB DSA Tutorial!

If the terminal correctly outputs the text above, your C development environment is configured successfully.


Detailed explanation of the compile command

The basic format of the GCC compile command is:



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

Common compile options:

Option Meaning Example
-o Specify the output file name gcc hello.c -o hello
-Wall Enable all common warnings to help find potential problems gcc -Wall hello.c -o hello
-g Generate debugging information for use with debuggers such as GDB gcc -g hello.c -o hello
-std=c99 Specify the use of the C99 standard gcc -std=c99 hello.c -o hello
-std=c11 Specify the use of the C11 standard gcc -std=c11 hello.c -o hello
-O2 Enable optimization (O2 level, balancing compile time and runtime efficiency) gcc -O2 hello.c -o hello

The compile command this tutorial recommends for daily use:



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

This command enables warnings, generates debugging information, and compiles your program using the C11 standard.