Visit Our Channel for Similar tutorials
In this tutorial, you will learn about variables and rules for naming a variable. You will also learn about different literals in C programming and how to create constants.
Variables
In programming, a variable is a container (storage area) to hold data.
To indicate the storage area, each variable should be given a unique name (identifier). Variable names are just the symbolic representation of a memory location. For example:
int playerScore = 95;
Here, playerScore is a variable of
int
type. Here, the variable is assigned an integer value 95
.Literals
Literals are data used for representing fixed values. They can be used directly in the code. For example: 1, 2.5, 'c' etc.
Here, 1,
2.5
and 'c' are literals. Why? You cannot assign different values to these terms.Constants
If you want to define a variable whose value cannot be changed, you can use the
const
keyword. This will create a constant. For example,const double PI = 3.14;
Notice, we have added keyword
const
.
Here, PI is a symbolic constant; its value cannot be changed.
const double PI = 3.14;
PI = 2.9; //Error
Comments
Post a Comment