Variables & Data Types
Learn C data types: int, float, double, char. Declare variables and print them with printf format specifiers.
25 min•By Priygop Team•Last updated: Feb 2026
Variables in C
In C, you must declare a variable's type before using it. C is statically typed — the type is fixed at compile time. The basic data types are int (integers), float (decimals), double (precise decimals), and char (single character). Variable names must start with a letter or underscore.
C Data Types & Format Specifiers
- int — Whole numbers: int age = 25; — use %d in printf
- float — Decimal numbers: float price = 9.99f; — use %f
- double — More precise decimals: double pi = 3.14159; — use %lf
- char — Single character: char grade = 'A'; — use %c
- char[] — String (array of chars): char name[] = "Alice"; — use %s
- Format specifiers tell printf what type to print
Variables Example
Example
#include <stdio.h>
int main() {
// Declaring variables
int age = 25;
float height = 5.9f;
double salary = 50000.50;
char grade = 'A';
char name[] = "Alice";
// Printing with format specifiers
printf("Name: %s\n", name);
printf("Age: %d\n", age);
printf("Height: %.1f feet\n", height);
printf("Salary: %.2f\n", salary);
printf("Grade: %c\n", grade);
return 0;
}Try It Yourself: Variables
Try It Yourself: VariablesC
C Editor
✓ ValidTab = 2 spaces
C|22 lines|508 chars|✓ Valid syntax
UTF-8