Input and output are your first window into what a C program is doing.
Direct answer
printf prints formatted text using specifiers such as %d for integers, %f for decimals, %c for characters and %s for strings. scanf reads input in the same format but needs the address of each variable, so use &. For lines of text, fgets is safer.
Example
#include <stdio.h>
int main(void) {
int age;
char name[30];
printf("Name: ");
scanf("%29s", name);
printf("Age: ");
scanf("%d", &age);
printf("%s is %d years old\n", name, age);
return 0;
}
Specifiers
| Specifier | Type |
|---|---|
%d | int |
%f | float or double |
%c | char |
%s | string |
%zu | size_t |
Common mistakes
- Missing
&inscanffor numbers. - Wrong specifier for the type.
- Using
scanf("%s")without a width limit.
Where Teyro fits
Teyro's C for Beginners course turns this into short lessons you can play in a few minutes a day. It has 78 lessons, and you can start free.
The bottom line
Match specifiers to types and limit input sizes.



