2 C Variables, Constants and Literals
2 C Variables, Constants and Literals
Fundamentals
(CO 101):
C Variables, Constants
and Literals
- Lakshita Agarwal
Department of Information Technology.
Mail ID- [email protected]
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.
• The value of a variable can be changed, hence the name
Rules for naming a
variables
• A variable name can only have letters (both
uppercase and lowercase letters), digits and
underscore.
• The first letter of a variable should be either a letter
or an underscore.
• There is no rule on how long a variable name
(identifier) can be.
• However, you may run into problems in some
compilers if the variable name is longer than 31
Rules for naming a
variables
• C is a strongly typed language. This means that the
variable type cannot be changed once it is declared.
• Here, the type of number variable is int.
• You cannot assign a floating-point (decimal) value 5.5
to this variable.
• Also, you cannot redefine the data type of the
variable to double.
• To store the decimal values in C, you need to declare
its type to either double or float.
Literals
programming.
mark etc.
double-quote marks.
white space
single character.
Constants
• %d for int
• %f for float
• %lf for double
• %c for char
THE END