C++ Language Primitives and
Datatypes
C++ Character Set
● The character set is a combination of English
language comprising of the Alphabets and the
White spaces and some symbols from the
mathematics including the Digits and the Special
symbols.
● C++ character set means the characters and the
symbols that are understandable and acceptable by
the C++ Program.
Type of C++ Character Sets
● The C++ has the following character set
Source Characters
Alphabets: a – z, A - Z
Digits: 0 – 9
Special characters
Escape Sequence/ Execution Characters.
C++ Special Characters
Escape sequence/execution
characters
● These are interpreted at execution time. The values of
these characters are implementation-defined.
● C++ uses some characters such as line feed, form
feed, tab, etc. through execution characters i.e. which
cannot be printed or displayed directly.
● Each of these characters has a unique implementation-
defined value that can be assigned to a single
character. Every escape sequence character starts
with a backslash ( \ ) followed by a character but both
are considered as a single character.
Escape Sequences/Characters
C++ Variables
● Variables are containers for storing data values. Variable
often have a type specified for them. These are the main datatypes for each
variable:
Datatype Size Description
bool 1 byte Stores true or false values
char 1 byte Stores a single character/letter/number, or ASCII values
int 2 or 4 bytes Stores whole numbers, without decimals
Stores fractional numbers, containing one or more decimals. Sufficient for storing 6-7
float 4 bytes
decimal digits
Stores fractional numbers, containing one or more decimals. Sufficient for storing 15
double 8 bytes
decimal digits
N* Store multiples characters, often in double quotes, with an escape character \0 at the end
string
1byte+1byte of those characters. Basic string size is determined by number of character in it.
Constants
● Constants are type of variables that would not change during the
execution/running of a program.
● We use the keyword const to declare such variables.
● this will declare the variable as "constant", which means unchangeable and
read-only
C++ Assignment Operator
● In C++ the equal sign = is used as an assignment
operator.
● Example 1: int num1 = 20; means “… create an integer
variable called num1 and store the integer 20 in it …”
● Example 2:
int num1 = 20; int num2 = 10;
int sum = num1 + num2;
The assignment is used in an expression. Simple
meaning add num1 and num2 and store the result in
the variable called sum.
C++ Arithmetic Operators
● C++ arithmetic operators are used to perform operations on
variables and values. The following is a list of some C++
arithmetic operators.
Relational Operators
● relational operators are used to compare two values (or variables). This is important
in programming, because it helps us to find answers and make decisions.
● The return value of a relational is either 1 or 0, which means true (1) or false (0).
These values are known as Boolean values, and you will learn more about them in
the Booleans and If..Else chapter.
Logic Operators
● As with relational operators, you can also test for true (1) or
false (0) values with logical operators.
● Logical operators are used to determine the logic between
variables or values:
IPC Class Activity 2
● Class Activity 1: Write a C++ Program to take as input the following:
fullname
Gender
DoB (Full Data of Birth)
● Then calculate the real Age of a person, which include years and months.
● Finally display the following:
if user is male:
"Hello Mr [fullname]. You are [age] years and [months] Old. Your date of
birth is [day/month/year]."
else gender is female:
"Hello Ms [fullname]. You are [age] years and [months] Old. Your date of
birth is [day/month/year]."