You are on page 1of 19

VARIABLES AND

DATA TYPES
I S A A C N A T H A N C A D O R N A
R I A N E K A I S E R I S I D
A N A M I K A E L A L A B A D O
VARIABLES
A variable is a memory region that serves as an essential storage
component in programming.
VARIABLES
VARIABLES
Example:
CONSTANTS
Constants in C++ are variables that are defined during initialization
and cannot be changed or revised afterward.
CONSTANTS
Example:
DATA TYPES
Data Type Description Byte Size Example Values

int integer 4 99, -123, 1001

float floating-point number 4 9.8, 3.14159

double floating-point 2.7182818284,


double 8
number 1.618033988

char character 1 B, 6, (

bool Boolean 1 true, false

void no type 0
DATA TYPES
DATA TYPES
DATA TYPES
String Character Array
Data Type Modifiers
Data type modifiers are used to modify the
behaviour and storage properties of basic data
types. int, double, and char are the data types
that can be modified using these modifiers.

Signed
Unsigned
Short
Long
SIGNED UNSIGNED
The signed modifier is The unsigned modifier
used to indicate that a indicates that a variable
variable can hold both can only hold non-
positive and negative negative values (zero or
values. However, most positive values). It is
built-in integer types often used when a
(like int) are signed by variable should not have
default in C++. So, you negative values, and you
rarely need to explicitly want to save memory by
use the signed keyword. not storing negative
numbers.
SHORT LONG
The short modifier is The long modifier is used
used to indicate that a to indicate that a
variable should be stored variable should be stored
using fewer bits than the using more bits than the
default data type. This default data type. This
is often used to save is used when you need to
memory when you know that store larger values that
a variable's value will cannot fit within the
fit within a smaller range of a standard data
range. type.
Rules in
naming a
variable
CPE 112
A variable needs to have
a unique name called an
identifier.
Identifiers can be more
descriptive (like age or
sum), or they can be
simple names like x and
y.
An identifier can consist of letters
(A-Z or a-z), numerals (0-9), and
underscores (_). Spaces and special
characters are not permitted. A
letter or an underscore can be the
only characters that start an
identifier. Because reserved
keywords in C++ have specified
meanings inside the language, they
cannot be used as identifiers. For
instance, because int already has a
predetermined meaning in C++, it
cannot be used as an identifier.
Compilation errors occur if these
are tried to be used as identifiers.
Within its namespace, the
identifier must be unique.
-Names can contain letters, digits and
underscores 1

-Names must begin with a letter or an


underscore (_) 2

general
-Names are case sensitive (myVar and
myvar are different variables) 3
rules for
identifiers
-Names cannot contain whitespaces or
special characters like !, #, %, etc. 4

-Reserved words, like C++ keywords such


as int, cannot be used as names 5

You might also like