23
ASSIGNED TO: SYED MUHAMMAD UMAIR SHAH ROLL NO. 12 MUHAMMAD FARHAN ROLL NO. 06 ABDUL HANAN ROLL NO. 02 WAQAS AZIZ ROLL NO. 05 MALIHA KHAN ROLL NO. 38 AZRA RAMZAN ROLL NO. 45 SYEDA IRAM ALI ROLL NO. 46 BS(CS) 2 ND SEMESTER INDUS INTERNATIONAL INSTITUTE D.G.KHAN

Data types

Embed Size (px)

Citation preview

ASSIGNED TO:

SYED MUHAMMAD UMAIR SHAH ROLL NO. 12

MUHAMMAD FARHAN ROLL NO. 06

ABDUL HANAN ROLL NO. 02

WAQAS AZIZ ROLL NO. 05

MALIHA KHAN ROLL NO. 38

AZRA RAMZAN ROLL NO. 45

SYEDA IRAM ALI ROLL NO. 46

BS(CS) 2ND SEMESTER

INDUS INTERNATIONAL INSTITUTE D.G.KHAN

1st Muhammad Farhan

DATA TYPES

In C++ , data are mainly divided into three

different types. These are:

1. Character data type

2. Integer data type

3. Float data type

Data type

A data type defines a set of values and a set of operation on those values. A C++ program may need to required different type of data. Each type required different type of memory.

It indicates the type of data that can be storein a variable

There are three basic data type.

Character

Integer

Float

This data type is used to store character values.

Characters may include letters, digits and

punctuation character. It take one byte in

memory i.e. ‘a’ and ‘@’ etc

Represented by the “char” data type.

Character data type

Character data type:

The “short” data type is the same size as “ char” usually one byte.

The character variable can store only one character

The Character range is “-128 to 127”

We can declared it as below.

Char a=‘A’

Char f=‘B’

Char z=‘D’ etc.

2nd Azra Ramzan

2. Integer data type:

A numeric value with no fraction is called integer data. It include both positive and negative values.

Represented by “int”

Int range –32,768 to 32,767

Some example of integer value are 56 and -12

Int size is ‘2’ bytes

Long int size ‘4’ bytes

We can declared it as below.

Int a=20;

Int b=40;

Int c=30;

Type of Integer data type

Int

Long int

Int data type

To store integer values and takes two byte in memory. i.e. int num;

Long int data type

To store large integer value. It has greater range and takes ‘4’ bytes in memory. i.e. long int num;

3rd Waqas Aziz

3: Float data type:

A numeric value with fraction is called real data type / float data type. It include both positive and negative values. i.e. 12.4 and -34.3

This data type are represented by “float”.

Float number are declared as

Float a=“40.00”

Float b=“23.04”

Float c=“10.3” etc

Type of float

Float

Double

Float data type

This data type is used to store real values and takes ‘4’ bytes in memory. i.e. Float num;

Double data type

It has great range as compared to float and takes ‘8’ byte in memory. i.e. Double num;

4th Syeda Iram Ali

Variable

A quantity whose values may change during the execution of the program is called variable.

It may be a numeric or non-numeric quantity

It represented by an identifier called variable name

A variable represents a memory location in the computer memory. Data is store into the memory location. The name of memory location or variable name remains fixed during the execution of the program but the data store in that location may change from time to time

Variable Declaration

A variable is case sensitive, that is, uppercase variables

are treated differently

Variable “SUM” is different from variable “sum”

Variable “NetPay” is different from variable “NETpay”

A variable cannot be the same as

Float X

Elwin

Main X

ping

Dote

Printf X

5th Syed Muhammad Umair Shah

Rules for variable Declaration

Variable may include letter, number and

underscore(_)

The first latter of the variable must be

character or underscore.

Blank spaces special symbols, commas are

not used

A variable can be ‘31’ character long for many

compilers

Key word are not used as variable name.

Variable Declaration

The process of specifying the name and it’s

data type is called variable declaration

All variables that are used in a program are

declared using variable declaration statement.

When a variable is declared a certain number

of bytes in the memory are allocated to the

variable name.

Syntax

Data- type variable name;

Example

Int num;

In this example variable num is declared which have integer data type

Char name;

In this example variable name is declared which have character data type

Float num;

In this example variable num is declared which have float data type

6th Abdul Hanan

Variable initialization

The process of assigning a value to a variable at the time of declaration is known as variable initialization.

The equal ( = ) is used to initialize a variable.

Variable name is given on the left side and value is given on the right side of equal sign.

Syntax

Type- name variable = value

Type name : it indicate the data type of variable

Variable : it is the name of variable

Value : it indicate the value initialize to variable.

Example:

Int num=5;

In this example variable num is declared which can have integer data type and contain the value ‘5’.

Char name =‘a’;

In this example variable name is declared which can have character data type and contain the value ‘a’.

7th Maliha Khan

Summary