Post Mid Week 1 B
Post Mid Week 1 B
C++ Literals
▪ Literals are fix values that can be used directly in code
5 3.9 ‘s’
Decimal: 8, -13, 22 etc -2.0 'a', 'm', 'F', '2', '}' "good“
Octal: 021, 077, 033 etc 0.0000234 "Earth is round\n“
Hexadecimal: 0x7f, 0x2a, -0.22E-5 ""
0x521 etc 77.98765
Learn for Success
What is constant?
“Constant is quantity that can not change its
value during execution”
▪ It can be store at location in the memory of
computer
CONSTANT
What is constant?
▪ Constants are said to be rvalues (for “right
values”) because they can be used on only
the right side of an assignment operator
▪ Character constant always a character
enclosed with single quotes (‘)
i.e ‘A’ , ‘9’, ‘@’
▪ String constant always enclosed with double
quotes
i.e “Pakistan”, “ ”, “IT Knowledge Seekers”
Learn for Success
DIFFERENCE
#define const
▪ is a preprocessor directive ▪ is c++ statement
▪Scope of the symbolic constant is global ▪Scope of const constant may local or global
▪Can’t have data type explicitly compiler ▪const constant have data type as a part of
judge it from literal its syntax
▪Not reserved a separate memory ▪ reserved a memory to hold literal
Learn for Success
PRACTICAL DEMO