Recent

Theme images by Storman. Powered by Blogger.

Recent in Sports

Home Ads

Comments

Ads

Random Posts

Sunday, 30 December 2018

Data Types and Program Execution in C++


Data Types in C++

Data types are used to identify the type of data and associated operation on it. C++ provides 3 types of data type such as:




a) Fundamental data type, b) Derived data type, c) User defined data type

a) Fundamental data type:

They are otherwise called primitive data type. Data type that is basically used in our program is called fundamental data types. These data types are not composed of other data types. C++ provides different fundamental data types as: int, float, char, double, void etc.

b) Derived data type:

Data types that are derived from fundamental data types are called derived data types. Commonly used derived data types are array, pointer, reference, etc.

c) User defined data type:

A user can create his own data type. Such data type is called user defined data type. The most commonly used user defined data types are class, structure, union etc.

Program Execution

A sequence of statements that are enclosed in open and close curely brace is called compound statement. In C++ a program code can be executed in different ways such as:

a) Sequence Execution:

A program execution in which each statement can be executed in a sequence manner(one by one) is called sequence execution.

b) Selective execution:

An execution of program code according to a condition is called selective execution. In case of selective execution, some part of the program code will be executed and at the same time some part will not be executed. There are different statements that are used for this purpose. They are named selective statements. Commonly used selective statements in C++ are ‘if’ statement and ‘switch’ statement.

c) Iterative Execution:

An execution of program code, that executes in a number of time, is called iterative execution. In case of iterative execution, same program code can be executed repeatedly according to a condition. The statement that is used for this purpose is called iterative statement.

Selective Statement:

To execute a program code selectively we can use different types of statements called selective statement. Commonly used selective statements are ‘’if’’ statement and ‘’switch’’ statements.

If statement:

It is a selective statement used to execute certain part of the programme code. In case of ‘if’ statement, it executes only certain part of the programme code according to the condition. If the condition is true, ‘if’ body will be executed, otherwise it executes the ‘else’ body.

Syntax:

if(condition)
{
if body
}
else
{
else body
}
Nested if:

An ‘if’ statement contains another ‘if’ statement inside it is called nested if.

Syntax:
if(condition)
{
if(condition)
{
if body
}
else
{
else body
}
}
else
{
else body
}

Switch statement:

Switch statement is also a selective statement used to execute a part of a program code. ‘Switch’ statement is a multiple branch selection statement. In case of ‘switch’ statement, it first evaluates the expression according to the value of expression, each case part will be executed. If no match is found, the default part will be executed. A switch statement contains another switch inside it, is called nested switch.

Syntax:

switch(expression)
{
case value 1:
......................
.....................
break;
case value 2:
....................
....................
default:
.........................
......................
}


0 on: "Data Types and Program Execution in C++"