The printf statement is your primary interface for sending data to standard out. In most cases, standard out is the screen. You can redirect it to a file or pipe it into another command, but for learning C, you are looking at text on your terminal.
Here is a basic program to demonstrate how it functions.
Save this as add.c. Compile it using gcc add.c -o add. Run it by typing ./add.
The output will be: 5 + 7 = 12.
Let’s break down what actually happens under the hood.
Variable Declaration and Assignment
The line int a, b, c; declares three integer variables. Integers hold whole numbers. No decimals.
Next, a = 5; initializes variable a with the value 5.
Then b = 7; sets b to 7.
The next line is where the assignment operator does its work: c = a + b;.
The computer takes the value in a (which is 5). It adds it to the value in b (which is 7). The result is 12. It then places that new value into variable c.
c is now assigned the value 12.
How printf Matches Placeholders
The printf statement prints the line “5 + 7 = 12”.
Look at the format string: "%d + %d = %d\n".
The %d placeholders act as slots for values. There are three %d placeholders here. At the end of the printf line, you see the three variable names: a, b, and c.
C matches them up in order.
The first %d corresponds to a. It substitutes 5.
The second %d corresponds to b. It substitutes 7.
The third %d corresponds to c. It substitutes 12.
The plus signs, the equals sign, and the spaces are part of the format string itself. They are embedded automatically between the %d operators exactly as you specified them in the code.
The result? A clean line of text on your screen.
Why does this matter? Because formatting output is how you debug. How do you know if your logic is working if you can’t see the numbers? printf tells you.
But it’s not just about printing. It’s about control. You decide what the user sees. You decide how the data is presented.
The \n at the end? That’s a newline. Without it, your next output might run right into this one.
It seems simple. It is simple. But it’s the foundation. Everything else builds on this.
You can redirect this output. You can format floats, strings, hex values. But you start here























