You are on page 1of 4

Data types

PRIMITIVE DATA TYPE


ABSTRACT OR USER DEFINED DATA TYPE
Primitive 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.
Abstract data types are defined by user itself. Like, defining a class in C++ or a structure.

Integer (int) & Character (char) are the most frequently used data types in C++
Type casting
Converting an expression of a given type into another type is known as type-casting.

Implicit conversions do not require any operator. They are automatically performed when a value is copied to a
compatible type.
C++ is a strong-typed language. Many conversions, specially those that imply a different interpretation of the value,
require an explicit conversion
Dynamic cast can be used only with pointers and references to objects. Its purpose is to ensure that the result of the
type conversion is a valid complete object of the requested class.
Static cast can perform conversions between pointers to related classes, not only from the derived class to its base,
but also from a base class to its derived.
Reinterpret cast converts any pointer type to any other pointer type, even of unrelated classes. The operation result
is a simple binary copy of the value from one pointer to the other.
Variables & its types

Each variable while declaration must be given a data type, on which the memory assigned to the variable depends.
Some of the variables are Bool, Char, Int & Float.

Bool. For variable to store Boolean values( True or False )


Char. For variables to store character types
Int. for variable with integral values
Float & Double are also types for variables with large and floating point values
Statements
Statements are fragments of the C++ program that are executed in sequence. The body of any function is a sequence of
statements

Any statement can be labeled, by providing a label followed by a colon before the statement itself.
An expression followed by a semicolon is a statement.
Compound statements or blocks are brace-enclosed sequences of statements.
Selection statements choose between one of several flows of control.
Iteration statements repeatedly execute some code.
Jump statements unconditionally transfer flow control.
Declaration statements introduce one or more identifiers into a block.
Try blocks provide the ability to catch exceptions thrown when executing other statements.

You might also like