Learn C like your first programming week actually matters.
This is built for someone who has only recently started using a laptop for real coding. Read the idea first. Run the example in a real C compiler. Record what happened. Only then unlock the explanation. Practice until you can write the next program without copying.
What Programming Really Is
Why computers need formal programming languages instead of ordinary English.
Introduction
A computer is extremely good at executing precise instructions and extremely bad at guessing what a human meant. When a person says “make the screen show my name,” another person can fill in missing details from context. A compiler cannot safely do that. A programming language therefore gives us strict rules for expressing operations, values, structure and order.
When and why?
Programming is useful whenever we want a machine to perform a process consistently: calculate, store, compare, transform, search, communicate or control hardware. C is particularly useful for learning how software relates closely to memory, types and machine operations.
How source code becomes a running program
- You write source code in a text editor/IDE.
- The preprocessor handles directives such as
#include. - The compiler checks C syntax and semantics and translates the source.
- The resulting program is linked with required components and can be executed.
Example 1 — your first tiny C program
#include <stdio.h>
int main(void)
{
printf("Hello, C.");
return 0;
}Example 2 — two printf calls
#include <stdio.h>
int main(void)
{
printf("C");
printf(" is precise.");
return 0;
}Activities · Chapter 1
Your First C Program, Line by Line
Understand #include, stdio.h, main, braces, statements, printf and return.
Introduction
Most beginner C programs look different on the surface but share a recognizable skeleton. Learning that skeleton reduces fear: you start seeing familiar parts instead of a wall of symbols.
When and why?
#include <stdio.h> gives the program access to declarations for standard input/output functions used in these lessons. main provides the normal entry point for a hosted C program. Braces group a block. A semicolon terminates many statements. These rules let the compiler parse the program unambiguously.
;, (), {} and #include each have a language-level purpose.Example 1 — structure
#include <stdio.h>
int main(void)
{
printf("I am learning C.");
return 0;
}Example 2 — comments
#include <stdio.h>
int main(void)
{
// The next line creates visible output.
printf("Comments are for humans.");
return 0;
}Activities · Chapter 2
printf, blank lines and a comment. Make it readable rather than decorative.Variables & Data Types
Give information names and choose an appropriate kind of value.
Introduction
Programs need memory to keep information while they run. A variable gives a stored value a name. A type tells C what kind of value is being represented and affects how that value is stored and used.
When and why?
Use variables whenever a value needs to be remembered, reused, changed, compared or included in a calculation. Choosing a type is part of designing the program: an age is normally a whole number, a price may require a decimal representation, and a single initial is a character.
int→ whole numbersfloat→ floating-point valuesdouble→ higher-precision floating-point valueschar→ one character
x = 5 assigns 5 to x. x == 5 asks whether x is equal to 5. You will use this distinction constantly.Example 1 — several types
#include <stdio.h>
int main(void)
{
int age = 20;
float height = 5.8f;
char grade = 'A';
printf("%d\\n", age);
printf("%.1f\\n", height);
printf("%c\\n", grade);
return 0;
}Example 2 — assignment changes the stored value
#include <stdio.h>
int main(void)
{
int score = 10;
score = 25;
printf("%d", score);
return 0;
}Activities · Chapter 3
Input with scanf()
Let the person running your program supply values at runtime.
Introduction
A fixed program always uses the values you typed into its source code. An interactive program can ask for information while it is running. scanf() is a standard input function used in basic C programs to read formatted values.
When and why?
Use input when values are not known until runtime: age, marks, quantity, distance, temperature and so on. The program becomes a reusable procedure instead of a single calculation with hard-coded values.
Why the &?
For an ordinary integer variable, scanf needs the variable's memory address so it knows where to store the value. The & operator obtains that address. You will learn pointers properly later; for now understand the reason, not just the pattern.
int age;, the ordinary beginner form is scanf("%d", &age);, not scanf("%d", age);.Example 1 — one input
#include <stdio.h>
int main(void)
{
int age;
printf("Enter your age: ");
scanf("%d", &age);
printf("You entered %d", age);
return 0;
}Example 2 — two inputs
#include <stdio.h>
int main(void)
{
int a, b;
scanf("%d %d", &a, &b);
printf("First = %d\\nSecond = %d", a, b);
return 0;
}Activities · Chapter 4
Operators & Expressions
Make values calculate, compare and form useful conditions.
Introduction
An expression combines values, variables and operators to produce a value. C provides arithmetic operators such as +, -, *, / and %, plus comparison and logical operators used for decisions.
Why integer division matters
When both operands are integers, division uses integer arithmetic. Therefore 17 / 5 produces 3, while 17 % 5 produces 2. This is not a bug; it is the defined operation for integer operands.
Comparison & logic
>, <, >=, <=, == and != compare values. && means AND, || means OR, and ! means NOT.
Example 1 — quotient and remainder
#include <stdio.h>
int main(void)
{
printf("%d\\n", 17 / 5);
printf("%d\\n", 17 % 5);
return 0;
}Example 2 — comparisons become 1 or 0
#include <stdio.h>
int main(void)
{
int a = 10;
printf("%d\\n", a > 5);
printf("%d\\n", a == 10);
printf("%d\\n", a != 10);
return 0;
}Activities · Chapter 5
Decisions with if / else
Teach the program to choose a path based on a condition.
Introduction
Most useful programs make decisions. A result may be pass or fail; a number may be positive, negative or zero; a purchase may qualify for a discount. if, else if and else let a program choose between these paths.
When and why?
Start with the decision in plain language: “if the number is divisible by 2, it is even.” Only after that translate the condition into C. This prevents syntax from becoming a substitute for reasoning.
Example 1 — even / odd
#include <stdio.h>
int main(void)
{
int n = 14;
if (n % 2 == 0)
printf("Even");
else
printf("Odd");
return 0;
}Example 2 — multiple branches
#include <stdio.h>
int main(void)
{
int marks = 78;
if (marks >= 90)
printf("A");
else if (marks >= 75)
printf("B");
else if (marks >= 40)
printf("C");
else
printf("F");
return 0;
}Activities · Chapter 6
Problem Solving Before Code
Learn a repeatable method for turning a problem into a program.
Introduction
Beginners often ask, “Which C statement should I use?” A better question is, “What exact steps solve this problem?” Syntax comes after the idea. Your workflow should be: understand → identify inputs and outputs → write the mathematics/logic → make an algorithm → code → test → debug.
Worked example — larger of two numbers
- Read
aandb. - Compare them using
a > b. - If true, the larger value is
a. - Otherwise the larger value is
b(including equality).
Example — run it before reading the explanation
#include <stdio.h>
int main(void)
{
int a, b;
printf("Enter two numbers: ");
scanf("%d %d", &a, &b);
if (a > b)
printf("Larger = %d", a);
else
printf("Larger = %d", b);
return 0;
}Activities · Chapter 7
Long Final Quiz
Concepts + code reading + actual output prediction.
Do the output questions without compiling first. You are training your ability to read code, not only your ability to run it.