Variables and Constants in C Programming
INTRODUCTION:-
In C programming, variables and constants are used to store data.
They are fundamental concepts that every beginner must understand before writing complex programs.
What is a Variable?
~A variable is a name given to a memory location used to store data.
The value of a variable can change during program execution.
Syntax:
data_type variable_name;
Example:
int age = 18;
float salary = 25000.5;
In this example:
- age is a variable of type int
- salary is a variable of type float
Rules for Naming Variables:-
- Must start with a letter or underscore
- Cannot start with a number
- Cannot use C keywords
- Case-sensitive (Age and age are different)
What is a Constant?
~A constant is a value that cannot be changed during program execution.
Example:
const int year = 2025;
**Here, the value of year cannot be modified.**
Types of Constants in C:-
- Integer constants (10, 100, -5)
- Floating constants (3.14, 2.5)
- Character constants ('A', 'b')
- String constants ("Hello")
Difference Between Variable and Constant
Variable : Constant
Value can change : Value cannot change
Uses memory location : Fixed value
Declared normally : Declared using const
Conclusion:-
Variables and constants are the building blocks of every C program.
Understanding them clearly will make learning operators and expressions much easier.
Comments
Post a Comment