C Environment Setup
In this page:
Compiler Overview
A compiler translates your human-readable C source code into machine instructions the processor can actually execute. GCC (GNU Compiler Collection) is the most widely used free compiler and is available on virtually every platform, including inside cookiescursor.com's own Try It tool.
Example: Compiler Overview
#include <stdio.h>
int main() {
printf("Compiled with GCC into a native executable.");
return 0;
}
Login to try C/C++/Java/PHP code in the editor
Text Editors
Any plain text editor can write C, but ones built for coding -- VS Code, Vim, or an IDE -- add syntax highlighting and error detection that catch typos before you even compile, saving you from cryptic compiler errors later.
Example: Text Editors
#include <stdio.h>
int main() {
printf("A good editor highlights syntax errors before you compile.");
return 0;
}
Login to try C/C++/Java/PHP code in the editor
Writing Your Code
Source files must use the .c extension so the compiler and your editor both recognize them as C code and apply the correct syntax rules; using the wrong extension is a common reason a compiler refuses to build a file at all.
Example: Writing Your Code
// Save this file as: hello.c
#include <stdio.h>
int main() {
printf("Saved with a .c extension so the compiler recognizes it.");
return 0;
}
Login to try C/C++/Java/PHP code in the editor
Compiling Your Code
Running gcc filename.c -o output reads your source file, checks it for syntax errors, and if it compiles cleanly, produces a binary executable -- any error messages printed here point to the exact line where the compiler got confused.
Example: Compiling Your Code
// Compile with: gcc hello.c -o hello
#include <stdio.h>
int main() {
printf("Run 'gcc hello.c -o hello' to compile this file.");
return 0;
}
Login to try C/C++/Java/PHP code in the editor
Running the Output
The compiled binary (typically named a.out on Linux/Mac or filename.exe on Windows) is a standalone program -- running it executes your code directly on the CPU, with no compiler or interpreter needed at that point.
Example: Running the Output
// After compiling: ./hello (Linux/Mac) or hello.exe (Windows)
#include <stdio.h>
int main() {
printf("This runs as a standalone compiled binary.");
return 0;
}
Login to try C/C++/Java/PHP code in the editor
Chapter Quiz — Complete all 21 topics to unlock
0/21 topics done
Complete these topics first:
- C Introduction
- C History & Features
- C Environment Setup
- C First Program
- C Syntax & Structure
- C Statements
- C Comments
- C Keywords & Identifiers
- C Data Types
- C Character Data Type
- C Numeric Data Types
- C Decimal (Floating-Point) Numbers
- C sizeof Operator
- C Extended Data Types
- C Type Conversion
- C Booleans
- C Variables
- C Changing Variable Values
- C Multiple Variables
- C Constants
- C Fixed-Width Integers