P-3.1 C: Types, Control Flow and Functions
Standard C as taught in the NPTEL and CS50 courses — written September 2026
What this is and why it exists
C is worth learning, and probably not because you will write much of it. It is worth learning because it makes explicit everything other languages do quietly.
Its type system is thin. Its checking is minimal. Its behaviour maps closely onto the machine model from the first module, which means the picture you built there is directly usable here.
One piece of advice belongs at the top rather than the end. Turn on every compiler warning from the first day. In C, the distance between a warning and a crash is often a few months.
The vocabulary
- Type — how many bytes a value occupies and how to read them.
- Implicit conversion — a change of type the compiler performs without being asked.
- Control structure — a conditional or a loop.
- Argument by value — the function receives a copy, not the original.
- Warning — the compiler telling you something is probably wrong.
- Undefined behaviour — a situation the language standard declines to define at all.
The mental model
A C type says two things: how many bytes, and how to interpret them. That is nearly all it says. Conversions between types happen quietly, in places you did not ask for, and they can lose information on the way. Knowing the actual sizes on your machine is where predicting any of this begins.
The control structures are ordinary. Their traps are famous and worth naming once. An assignment written where a comparison was meant. An off-by-one at a boundary. A stray semicolon that ends a loop body before it began. None of these is subtle in hindsight, and all of them compile.
Functions pass copies. A function receives a copy of each argument, so it cannot change a caller's variable. That single fact is why pointers appear as early as they do in every C course, including this one. They are the answer to a problem you meet in week one.
Now, warnings. The compiler already knows about a large share of the mistakes you are about to make. By default it stays quiet about most of them. Turning them all on and treating them as failures is the cheapest habit available in this module. It costs one flag and saves whole evenings.
Finally, undefined behaviour, which is the idea that makes C different from most languages you will meet. Some mistakes are not errors. They are situations the standard declines to define, which means the compiler is permitted to do anything at all. Including work perfectly, for a year, until the day it does not. This is why C rewards care rather than cleverness.
What you should now be able to explain or do
Write, compile and run a C program using its types, loops, conditionals and functions. Say what a type actually tells the compiler. Name the three classic control-flow traps and recognise them in code. Explain why a function cannot change its caller's variable, and what that implies. Turn every warning on and fix all of them. Say what undefined behaviour means and why it is worse than an error.
Check yourself
What does a C type tell the compiler?
How many bytes the value takes and how to read them. Very little else, which is why conversions can quietly lose information.
Why do pointers turn up so early in C?
Because arguments are copies. A function that must change a caller's variable has to be handed its address, and that need appears immediately.
Why turn on every compiler warning?
The compiler already recognises many of the mistakes you are about to make. By default it does not mention most of them.
What is undefined behaviour?
A situation the standard does not define, so the compiler may do anything. It is not an error and nothing is obliged to report it.
Why is undefined behaviour worse than a plain error?
An error stops you. Undefined behaviour can work perfectly for a long time and then stop working for reasons unrelated to what you changed.
Go deeper
We haven't checked most of these for screen reader use yet.
- CS50x: Introduction to Computer Science · Harvard / CS50 · Courseneeds a free account
Back to C: Types, Control Flow and Functions: work through the checklist