C Programming: Memory, Pointers and the Stack ยท C Basics
Print numbers, decimals and characters with printf and format codes like %d, %.2f and %c.
#include <stdio.h>
int main(void) {
int age = 21;
double price = 4.5;
char grade = 'A';
printf("Age: %d\n", age);
printf("Price: %.2f\n", price);
printf("Grade: %c, padded: [%5d]\n", grade, age);
return 0;
}age is an int: a whole number, stored on the stack.price is created on the stack with the value 4.5.age. \n moves to a new line.0.