C Introduction
In this page:
What is C?
C is a general-purpose, procedural programming language built around functions and statements rather than objects.
It gives you fine control over how a program uses memory and the CPU, which is why it still underlies so much of the software you use every day without seeing it.
Example: What is C?
// Include standard input/output (printf, scanf)
#include <stdio.h>
// Program execution starts in main()
int main() {
// Declare total and set it to 0
int total = 0;
// Loop: repeat while the condition holds
for (int i = 1; i <= 5; i++) {
total += i;
}
// Print formatted text to the screen
printf("Total: %d", total);
// Return 0 to signal that the program finished successfully
return 0;
}
Login to try C/C++/Java/PHP code in the editor
Why Learn C?
Learning C forces you to understand what's actually happening under the hood -- how variables occupy memory, how a program is compiled into machine instructions, and how a CPU executes them one at a time.
That mental model carries over directly into languages like C++, Java, and even Python.
Example: Why Learn C?
// Include standard input/output (printf, scanf)
#include <stdio.h>
// Program execution starts in main()
int main() {
// Declare x and set it to 10
int x = 10;
// Print formatted text to the screen
printf("Value: %d, Size in memory: %zu bytes", x, sizeof(x));
// Return 0 to signal that the program finished successfully
return 0;
}
Login to try C/C++/Java/PHP code in the editor
How C Works
A C program is first translated by a compiler into an intermediate object file, then linked into a native executable containing raw machine instructions.
Unlike interpreted languages, there's no runtime translating your code as it runs -- the CPU executes your logic directly.
Example: How C Works
// Include standard input/output (printf, scanf)
#include <stdio.h>
// Program execution starts in main()
int main() {
// Print formatted text to the screen
printf("This program runs as compiled machine code, no interpreter needed.");
// Return 0 to signal that the program finished successfully
return 0;
}
Login to try C/C++/Java/PHP code in the editor
Applications of C
Operating system kernels (Linux, parts of Windows), database engines like SQLite and PostgreSQL's core, and most other language runtimes are themselves written in C, because it gives predictable performance with almost no hidden overhead.
Example: Applications of C
// Include standard input/output (printf, scanf)
#include <stdio.h>
// Program execution starts in main()
int main() {
// Print formatted text to the screen
printf("C powers OS kernels, database engines, and language runtimes.");
// Return 0 to signal that the program finished successfully
return 0;
}
Login to try C/C++/Java/PHP code in the editor
Benefits of C
Because C compiles to native code and lets you manage memory manually with pointers, programs written in it tend to be faster and use less RAM than equivalent code in higher-level languages -- at the cost of you being responsible for that memory yourself.
Example: Benefits of C
// Include standard input/output (printf, scanf)
#include <stdio.h>
// Program execution starts in main()
int main() {
// Declare value and set it to 100
int value = 100;
int *ptr = &value;
// Print formatted text to the screen
printf("Direct memory control via pointer: %d", *ptr);
// Return 0 to signal that the program finished successfully
return 0;
}
Login to try C/C++/Java/PHP code in the editor
- Assuming C is interpreted like a script, when a C source file must be compiled (for example
gcc main.c -o main) before you can run it. - Expecting C to have built-in strings, classes or automatic memory management, when strings are
chararrays and memory is your responsibility. - Confusing C with C++ and using
coutorclassin a.cfile, which C compilers reject.
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