Welcome to the first article in my "Programming Foundation with C" series.
Before we start writing C code, there are three core concepts you need to understand. Master these and the rest of programming starts to make sense:
Variables
Data Types
Arrays
Let's get into it.
1. Variables
When you write a program, you almost always need to work with values — names, numbers, scores, ages, whatever. Those values need to live somewhere while your program is running. That somewhere is your computer's memory — the RAM.
A variable is just a named location in that memory. You give it a name so you can find it and use it later.
Here's the simplest example:
#include <stdio.h>
int main() {
int age = 25;
printf("%d", age);
return 0;
}
This program stores the number 25 in memory, labels that location age, and prints it. That's it. Clean and simple.
Naming Rules (you must follow these)
Cannot start with a number → 1name ❌
Cannot contain spaces → my age ❌
Cannot be a reserved word → int, for, while ❌
Best Practices (you should follow these)
Use meaningful names → age is better than a
Use camelCase or snake_case → userName or user_name
2. Data Types
When you create a variable, you also have to tell the computer what kind of value you're storing. Is it a whole number? A decimal? A single character? That's what data types are for.
C is strict about this — you can't just throw any value into any variable. You have to declare the type upfront.
The Core Data Types
| Type | What it stores | Example |
|---|---|---|
| int | Whole numbers | 25, -7, 1000 |
| float | Decimal numbers (single precision) | .14, -0.5 |
| double | Decimal numbers (double precision, more accurate) | .14,-0.5 |
| char | A single character | 'A', 'z', '3' |
int score = 100;
float temperature = 36.6;
char grade = 'A';
Quick summary: A variable has three things — a type, a name, and a value. Always define all three clearly.
3. Arrays
So far we've stored one value per variable. But what if you need to store a list of values — like a full squad of operators?
That's where arrays come in.
An array is a collection of values grouped under one variable name. Each value has an index (its position in the list), starting from 0.
char team[] = {"Price", "Soap", "Gaz", "Ghost"};
(Yeah, if you know these guys — you're a real one. And yes, they ruined it.)
Accessing values by index:
team[0] // "Price"
team[1] // "Soap"
team[2] // "Gaz"
team[3] // "Ghost"
⚠️ Note: In most cases, arrays hold values of the same data type. A list of integers, a list of characters — not a mix.
Wrapping Up
You now know the three building blocks that almost every program is built from:
Variables — named locations in memory that hold values
Data Types — define what kind of value a variable holds
Arrays — group multiple values under one name
These aren't just C concepts — they exist in every programming language. Learning them in C means you're learning them properly, from the ground up.
Next article, we'll go deeper. Stay tuned.
If you found this helpful — or if I got something wrong — drop a comment. Whether you're a beginner or a veteran, I want to hear from you.
Happy coding. 🖥️
Top comments (1)
Super