A structured lesson workspace with readable content, hands-on examples, and a clean path to completion.
The register storage class was a suggestion to the compiler: keep this variable in a CPU register for fast access. In the 1970s, when compilers were simple and registers were scarce, this hint mattered. Today, every optimizing compiler ignores it. GCC, Clang, and MSVC perform register allocation far more effectively than a human can. The only remaining effect of register is that you cannot take the address of a register variable with &. That restriction is the only reason the keyword still exists.
#include <stdio.h>int main(void) {register int counter = 0;for (register int i = 0; i < 1000000; i++) {counter++;}printf("counter: %d\n", counter);return 0;}
The compiler rejects &x because a register variable might not have a memory address. In practice, the compiler ignores the register hint and puts x in memory anyway, but the language rule still forbids taking the address. This is the only observable effect of register in modern C. In C17, register is still a keyword. In C23, it is retained for backward compatibility but has no effect whatsoever.
Compile with -O2 or -O3. The compiler's register allocator considers the entire function, the calling convention, the available registers, and the instruction pipeline. It makes better decisions than you can. If you need to ensure a variable stays in a register for performance, profile first, then consider compiler-specific attributes or inline assembly. The register keyword is not the tool.
register is a fossil. It reminds us that C was designed for PDP-11 compilers with minimal optimization. Today, trust the compiler. Use -O2. Profile before optimizing. And do not use register in new code. It communicates nothing except that the code was written by someone reading a 1980s textbook. Preprocessor module complete. Next: advanced C topics, where we tackle scope, error handling, 2D arrays, threads, and the questions that separate intermediate C programmers from advanced ones.
Finish the lesson once you have worked through the material. This awards ★ 20 XP.