A variable is a name given to a memory location that stores a value. This value can change during the execution of a program.
Syntax:
datatype variableName = value;
Example:
int age = 20;
float height = 5.8;
char grade = 'A';
Age and age are different)Data types tell the compiler what kind of data a variable can hold. C has several types:
Stores whole numbers without decimals.
int num = 25;
Stores decimal numbers (single precision).
float temp = 36.6;
Stores larger decimal numbers with more precision than float.
double distance = 1234.56789;
Stores a single character enclosed in single quotes.
char letter = 'B';
Represents no value. Commonly used in functions to indicate no return value.
void printHello() {
printf("Hello");
}
Used to store smaller or larger integers.
short a = 100;
long b = 1000000;
#include <stdio.h>
int main() {
int age = 20;
float marks = 87.5;
char grade = 'A';
printf("Age: %d\n", age);
printf("Marks: %.1f\n", marks);
printf("Grade: %c\n", grade);
return 0;
}
A variable is a name given to a memory location that stores a value. This value can change during the execution of a program.
Syntax:
datatype variableName = value;
Example:
int age = 20;
float height = 5.8;
char grade = 'A';
Age and age are different)Data types tell the compiler what kind of data a variable can hold. C has several types:
Stores whole numbers without decimals.
int num = 25;
Stores decimal numbers (single precision).
float temp = 36.6;
Stores larger decimal numbers with more precision than float.
double distance = 1234.56789;
Stores a single character enclosed in single quotes.
char letter = 'B';
Represents no value. Commonly used in functions to indicate no return value.
void printHello() {
printf("Hello");
}
Used to store smaller or larger integers.
short a = 100;
long b = 1000000;
#include <stdio.h>
int main() {
int age = 20;
float marks = 87.5;
char grade = 'A';
printf("Age: %d\n", age);
printf("Marks: %.1f\n", marks);
printf("Grade: %c\n", grade);
return 0;
}