Programing
Fundamentals Lab 5
By
Alia Naseem
Lecturer FUUAST
Outline
Size of all data types.
Rangeof possible values (maximum
& minimum) by each data type.
Data type modifiers.
Data type size and value range
Whenever a variable is defined in C+
+, the compiler allocates some
memory for that variable based on
the “data-type” with which it is
declared. Every data type.
requires a different amount of
memory.
Basically, The type of a variable
determines how much space it
occupies in storage.
Buit-In|Derived|User-defind Data
type
Primitive (Basic) Data Types
These data types are built-in or predefined
data types and can be used directly by the
user to declare variables. example: int,
char , float, bool etc. Primitive data types
available in C++ are:
• Integer
• Character
• Boolean
• Floating Point
• Double Floating Point
• Valueless or Void
Derived Data Types
The data-types that are derived from
the primitive or built-in data types
are referred to as Derived Data
Types. These can be of four types
namely:
• Function
• Array
• Pointer
• Reference
We will discuss derived data types in the incoming
classes.
User-Defined Data Types
These data types are defined by user
itself. Like, defining a class in C++ or
a structure. C++ provides the
following user-defined data types:
• Class
• Structure
• Enumeration
We will discuss user-defined data types in the incoming
classes.
Built-In data types cont…
Integer: Keyword used for integer data types is int.
Integers typically requires 4 bytes of memory space
and ranges from -2147483648 to 2147483647.
Character: Character data type is used for storing
characters. Keyword used for character data type
is char. Characters typically requires 1 byte of memory
space and ranges from or 0 to 255.
Boolean: Boolean data type is used for storing boolean
or logical values. A boolean variable can store
either true or false. Keyword used for boolean data
type is bool.
Built-In data types cont…
Floating Point: Floating Point data type is used for storing single precision
floating point values or decimal values. Keyword used for floating point data
type is float. Float variables typically requires 4 byte of memory space
and ranges from 1.2E-38 to 3.4E+38.
e.g 1.2E-38 is the same as 1.2x10^-38. E is for
exponent actally.
Double Floating Point: Double Floating Point data type is used for storing
double precision floating point values or decimal values. Keyword used for
double floating point data type is double. Double variables typically
requires 8 byte of memory space and ranges from 2.3E-308 to
1.7E+308
Void: void data type represents a valueless entity. Void data type is used
for those function which does not returns a value.
Note : Above values may vary from compiler to compiler.
Can we change the memory space and
range of these data types????
Data type Modifiers in C+
+
Modifiers are prefixed with basic data
types to modify (either to increase or
decrease) the amount of storage space
allocated to variables.
Modifiers are prefixed with primitive data
types only.
The data type modifiers are listed here −
• signed
• unsigned
• long
• short
Data type Modifiers in C+
+
WHY MODIFIERS?
Modifiers helps to fit to a situation
more precisely.
short: it applies to int and reduces
the size of int to 2 bytes.
long: it applies on int and double data
type and double the size of int(4 to 8
byte)and double(8 to 16 bytes).
unsigned: it accepts only +ve values
signed: it accept both +ve and -ve
values.
Practice some programs that involves
C++ modifiers.