Professional Documents
Culture Documents
LITERALS AND
CONSTANTS IN
C++
What is C++ Variables?
int sum;
sum=12+5;
EXAMPLE:
int age, id_number, school_name;
int sum, a=9, b=10, c=56;
int a; sum=a+b;
float =
DATA Variable
TYPE name
RULES OF NAMING A VARIABLE
• Example:
• DECIMAL:
5, 87, 34, 0
• OCTAL:
232, 987, 078
FLOATING-POINT LITERALS
• Example:
-2.0
0.00034204
0.3475
CHARACTERS
• EXAMPLE:
• ‘a’, ‘F’, ‘y’, ‘2’
CHARACTERS
• EXAMPLE:
• ‘a’, ‘F’, ‘y’, ‘2’
STRING LITERALS
• Sequence of characters enclosed in double-
quote marks.
• EXAMPLE:
• “good thing” - string constant
- null string constant
• “” - string constant of six white space
• ““ - string constant having a single
• “x” character
- prints string with a newline
• “Earth is round\n”
ESCAPE SEQUENCE LITERALS
• Use characters that cannot be typed or has
special meaning.
• EXAMPLE:
What is C++ Constants?