
Variables in C
? Variables in C
A variable is a name that stores a value — like a container in memory you can use and update.
? Syntax
type variableName = value;
Example:
Data Type Description Example int
Integer int x = 10;
float
Floating point number float pi = 3.14;
char
Single character char grade = 'A';
double
Double precision float double d = 9.81;
char[]
String (array of chars) char name[] = "Alice";
? Declaring Multiple Variables
int a = 5, b = 10, c;
? Rules for Naming Variables
Must start with a letter (or
_
)Can contain letters, numbers, and underscores
Case-sensitive (
age
?Age
)Avoid keywords (
int
,return
, etc.)
? Example Program
#include <stdio.h>int main() { int age = 20; float gpa = 3.75; char grade = 'A'; printf("Age: %d\n", age); printf("GPA: %.2f\n", gpa); printf("Grade: %c\n", grade); return 0;}
? Tip:
Always initialize your variables — C doesn't automatically set them to zero!