Variables and printf in C
Declaring typed variables and printing them.
void describe(void) {
int count = 42;
double ratio = 3.5;
char grade = 'A';
const char *name = "typestar";
printf("%s: %d items, %.1f ratio, grade %c\n",
name, count, ratio, grade);
}
How it works
- Each variable has an explicit type:
int,double,char. - A
const char *points at a string literal. printfinterpolates with%d,%.1f,%c,%s.
Keywords and builtins used here
charconstdescribedoubleintvoid
The run, in numbers
- Lines
- 9
- Characters to type
- 184
- Tokens
- 49
- Three-star pace
- 80 tpm
At the three-star pace of 80 tokens a minute, this run takes about 37 seconds.
Step 1 of 7 in Variables & types, step 1 of 35 in Language basics.