Variables and Constants
Variables and Constants
Variables and Constants
For example:
int playerScore = 95;
In C programming, you have to declare a variable before you can use it.
2.4 Memory Concepts
• Variables
– Variable names correspond to locations in the
computer's memory
– Every variable has a name, a type, a size and a value
– Whenever a new value is placed into a variable
(through scanf, for example), it replaces (and
destroys) the previous value
– Reading variables from memory does not change
them
• A visual representation
integer1 45
4
What is a Variable? symbol table?
A variable name can have letters (both uppercase and lowercase letters), digits
and underscore only.
There is no rule on how long a variable can be. However, the first 31 characters of
a variable are discriminated by the compiler. So, the first 31 letters of two variables
in a program should be different.
Constants/Literals
For example:
-2.0 0.0000234 -0.22E-5
Note: E-5 = 10-5
Character constants
A character constant is a constant which uses single quotation around
characters.
String constants are the constants which are enclosed in a pair of double-quote
marks.
For example:
"good" //string constant
"" //null string constant
" " //string constant of six white space
"x" //string constant having single character.
"Earth is round\n“ //prints string with newline
Enumeration constants
For example:
Here, color is a variable and yellow, green, black and white are the enumeration
constants having value 0, 1, 2 and 3 respectively. For more information, visit
page: C Enumeration.