C Essentials 1 (C101): Program Structure, Types, Control Flow and Console I/O
Domain 1 - C Essentials 1 covers the foundation of the language: how a source file becomes a running program, how objects are declared and typed, how expressions evaluate, and how control flow and formatted console I/O behave. Items are typically short programs or single expressions whose printed output you must predict exactly, so precision about types and evaluation order matters more than writing large programs.
Program structure and build model
A program is one or more translation units, each preprocessed, compiled, then linked into an executable. Execution begins at main, which must return int; return 0; reports success. Every object must be declared before use, statements end with semicolons, and blocks { } open a new scope. #include <stdio.h> is required for printf and scanf.
Types and expressions
Fundamental types are char, int, float, double and _Bool, plus short, long, long long and signed/unsigned; sizeof yields a size_t byte count. Integer division truncates toward zero; % accepts only integer operands; mixing in a floating type promotes the expression to floating point. Precedence runs multiplicative, additive, relational, equality, bitwise AND/XOR/OR, logical AND, logical OR, then right-associative assignment. && and || short-circuit, so the right operand may never be evaluated.
Control flow and formatted I/O
else binds to the nearest unmatched if. switch needs an integer controlling expression, case labels must be integer constant expressions, and execution falls through until break. do-while runs its body at least once. printf conversions must match argument types: %d for int, %c for char, %f for float (promoted) and double, %s for strings, %% for a literal percent. scanf needs %lf for double but %f for float.
Worked example
int a = 5, b = 2; double d = a / b; printf("%f", d); prints 2.000000. The division is evaluated first with two int operands, so the quotient is truncated to 2 and only then converted to double. Writing (double)a / b forces floating division and prints 2.500000.
Traps
Omitting & in scanf for scalar arguments; = where == is meant; a stray semicolon after if (...); reading an uninitialized variable; assuming plain char is signed; and passing a double to scanf with %f.