DevAcademia
C++C#CPythonJava
  • C Basics

  • Introduction to C
  • Getting Started with C
  • C Syntax
  • C Output
  • C Comments
  • C Variables
  • C Data Types
  • C Constants
  • C Operators
  • C Booleans
  • C If...Else Statements
  • C Switch Statement
  • C While Loops
  • C For Loops
  • C Break and Continue
  • C Strings
  • C User Input
  • C Memory Address
  • C Pointers
  • C Files
  • C Functions

  • C Functions
  • C Function Parameters
  • C Scope
  • C Function Declaration
  • C Recursion
  • C Math Functions
  • C Structures

  • C Structures
  • C Structs & Pointers
  • C Unions
  • C Enums

  • C Enums
  • C Memory

  • C Allocate Memory
  • C Access Memory
  • C Reallocate Memory
  • C Deallocate Memory
  • C Structs and Memory
  • C Memory Example
  • C Quiz

  • C Quiz
  • C Basics

  • Introduction to C
  • Getting Started with C
  • C Syntax
  • C Output
  • C Comments
  • C Variables
  • C Data Types
  • C Constants
  • C Operators
  • C Booleans
  • C If...Else Statements
  • C Switch Statement
  • C While Loops
  • C For Loops
  • C Break and Continue
  • C Strings
  • C User Input
  • C Memory Address
  • C Pointers
  • C Files
  • C Functions

  • C Functions
  • C Function Parameters
  • C Scope
  • C Function Declaration
  • C Recursion
  • C Math Functions
  • C Structures

  • C Structures
  • C Structs & Pointers
  • C Unions
  • C Enums

  • C Enums
  • C Memory

  • C Allocate Memory
  • C Access Memory
  • C Reallocate Memory
  • C Deallocate Memory
  • C Structs and Memory
  • C Memory Example
  • C Quiz

  • C Quiz

Loading C tutorial…

Loading content
C BasicsTopic 2 of 64
←PreviousPrevNextNext→

Install a C Compiler

To run C programs, you need a C compiler. Common choices are: - GCC (Linux, macOS via Homebrew/MacPorts, Windows via MinGW-w64 or WSL) - Clang (macOS via Xcode Command Line Tools, Linux packages) - MSVC (Windows, via Visual Studio or Build Tools) Quick checks after installation: - GCC: `gcc --version` - Clang: `clang --version` - MSVC: Open the "Developer Command Prompt for VS", then `cl`

Note: On Windows, two popular routes are MinGW-w64 (GCC) or MSVC (Visual Studio). You can also use WSL to get a Linux-like GCC/Clang environment. Online compilers are fine for quick tests.

Write Your First Program

Create a new file named `hello.c`. Copy the code into it. This simple program prints a message to the screen. The `\n` ensures the output ends with a newline.

Example
#include <stdio.h>

int main(void) {
    printf("Hello, World!\n");
    return 0;
}
Output
Hello, World!

Compile the Program

Open your terminal (or command prompt) in the folder where `hello.c` is saved. Then run one of the following: GCC (Linux/macOS/MinGW-w64): - `gcc -std=c17 -Wall -Wextra -Wpedantic hello.c -o hello` Clang (Linux/macOS): - `clang -std=c17 -Wall -Wextra -Wpedantic hello.c -o hello` MSVC (Developer Command Prompt): - `cl /std:c17 /W4 hello.c` These commands produce an executable named `hello` (or `hello.exe` on Windows).

Note: The warning flags (`-Wall -Wextra -Wpedantic` or `/W4`) help catch common issues early.

Run the Program

Once compiled, run the program: - On Linux/macOS: `./hello` - On Windows (PowerShell or CMD): `.\hello.exe`

Hello, World!
✅ Congratulations! You have successfully written, compiled, and run your first C program.

Troubleshooting Tips

- If `gcc` or `clang` isn't found, confirm installation and PATH settings. - On macOS, you may need: `xcode-select --install` for Command Line Tools. - On Windows with MSVC, always use the "Developer Command Prompt for VS" before running `cl`. - If your output appears without a newline, add `\n` in `printf`.

C BasicsTopic 2 of 64
←PreviousPrevNextNext→