0% found this document useful (0 votes)
8 views7 pages

Post Mid Week 1 B

Computer slides Programming fundamentals

Uploaded by

asgharzainab877
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views7 pages

Post Mid Week 1 B

Computer slides Programming fundamentals

Uploaded by

asgharzainab877
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Learn for Success

C++ Literals
▪ Literals are fix values that can be used directly in code

5 3.9 ‘s’

INTEGER LITERAL FLOATING POINT CHARACTER STRING LITERAL


LITERAL LITERAL
Numeric value without Numeric value with Single character sequence of
fractional part fractional part enclosed in single characters
quotes enclosed in
double-quote

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

NUMERIC CONSTANTS CHARACTER CONSTANTS

INTEGER CONSTANTS REAL CONSTANTS SINGLE CHAR CONSTANTS STRING CONSTANTS


Learn for Success

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

▪ The character constant ‘\0’ is known as null


character
▪ The memory will be allocate to a constant
while literal are values that store in the
allocated memory.
Learn for Success

How to create constants in c++


There are two method to define constants in c++
1. By using #define preprocessor directive
2. By using const keyword
#define preprocessor directive const keyword
Syntax Syntax
#define identifier value const data type identifier = value;
Example Example
#define PI 3.1416 const float PI=3.1416;
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

You might also like