C Installation

To run C programs on your computer you need a C compiler. The most popular free compiler is GCC. Mac also has Clang, which works in the same way.

Install on Windows

Install MSYS2 or MinGW-w64, which gives you the gcc command. After the installation, add its bin folder to the PATH setting. Many beginners also use the Code::Blocks IDE, which comes with a compiler included.

Install on macOS

Open Terminal and run this command. It installs the Apple command line tools, with Clang.

xcode-select --install

Install on Linux

sudo apt install gcc

On Fedora use sudo dnf install gcc.

Check the installation

gcc --version

If it shows a version number, the compiler is ready.

Write, compile and run

Create a file named hello.c with this code.

#include <stdio.h>

int main(void) {
    printf("Hello from C\n");
    return 0;
}

Compile it and run it from the terminal.

gcc hello.c -o hello
./hello

Output:

Output of the above program is

Hello from C

Note: On Windows the executable is named hello.exe and you run it with hello only. You can also use any editor, like VS Code, for writing the code.

Next: C Basic Program Structure.


Congratulations! Chapter Finished. Learn more about the similar topics:
Exercises & Assignments
No Content Found.
Interview Questions & Answers
No Content Found.