data type. a data type defines a set of values that a variable can store along with a set of...

23
Data Type popo

Upload: wesley-cannon

Post on 23-Dec-2015

214 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Data Type. A data type defines a set of values that a variable can store along with a set of operations that can be performed on that variable. Common

Data Type

popo

Page 2: Data Type. A data type defines a set of values that a variable can store along with a set of operations that can be performed on that variable. Common

Data Type• A data type defines a set of values that a

variable can store along with a set of operations that can be performed on that variable.

• Common data types are integer, character, and real.

popo

Page 3: Data Type. A data type defines a set of values that a variable can store along with a set of operations that can be performed on that variable. Common

Data Type• Data Types

popo

Page 4: Data Type. A data type defines a set of values that a variable can store along with a set of operations that can be performed on that variable. Common

Data Type

popo

Page 5: Data Type. A data type defines a set of values that a variable can store along with a set of operations that can be performed on that variable. Common

Data Type• Basic Data type(Primary, fundamental)• Integers, Character and Floating point

IntegerSinged type Unsigned type

int unsigned intshort int unsigned short intlong int unsigned long int

CharacterSigned char

Unsigned char

Floating Pointfloat double long double

Primary Data type

popo

Page 6: Data Type. A data type defines a set of values that a variable can store along with a set of operations that can be performed on that variable. Common

Data Type• Basic Data type(Primary, fundamental)• Integers• Signed and unsigned types

• Signed– can store + and –ve integers• Unsigned– can store only +ve integers

IntegerSinged type Unsigned type

int unsigned intshort int unsigned short intlong int unsigned long int

popo

Page 7: Data Type. A data type defines a set of values that a variable can store along with a set of operations that can be performed on that variable. Common

Data Type• Basic Data type(Primary, fundamental)• Signed type integers• int :- integers are whole numbers, capable to

storing numeric value without decimal places.• any number in the range -32768 to 32767• It occupies 2 bytes of memory• Long int :- required 4 bytes of memory.• Value range from -2147483648 to 2147483647• Long int variable can declare• long int a,b; or long a;

popo

Page 8: Data Type. A data type defines a set of values that a variable can store along with a set of operations that can be performed on that variable. Common

Data Type• Basic Data type(Primary, fundamental)• Signed type integers• Short integers :- need less space in memory (same

as int)• Short int variable can delare• short int a; or int a;( both are same)

popo

Page 9: Data Type. A data type defines a set of values that a variable can store along with a set of operations that can be performed on that variable. Common

Data Type• Basic Data type(Primary, fundamental)• Unsigned integers• unsigned integers :- some time if we know in advanced,

the value stored in an integer variable is always be +ve.• Such situations we can declared the variable as

unsigned int• The range permissible integer value will shift from 0 to

65535 ie double the size of int• Unsigned integer variable can declare• unsigned int a; or unsigned a;( both are same)

popo

Page 10: Data Type. A data type defines a set of values that a variable can store along with a set of operations that can be performed on that variable. Common

Data Type• Basic Data type(Primary, fundamental)• Unsigned integers• unsigned short integers :- same as unsigned int• unsigned long integers :- • Range 0 to 42949672954 (double size of long int)• Unsigned long integer variable can declare• unsigned long int a;

popo

Page 11: Data Type. A data type defines a set of values that a variable can store along with a set of operations that can be performed on that variable. Common

Data Type• Basic Data type(Primary, fundamental)• Characters• Signed and unsigned types• Both occupy 1 byte of memory• But having different range• Signed char is same as ordinary char and has range -128

to 127• Unsigned char range from 0 to 255• Example• cnsigned char a;• char a;

CharacterSigned char

Unsigned char

popo

Page 12: Data Type. A data type defines a set of values that a variable can store along with a set of operations that can be performed on that variable. Common

Data Type• Basic Data type(Primary, fundamental)• Floating point• A float variable occupy 4 bytes of memory• Range from 3.4E-38 to 3.4E+38• Double occupy 8 bytes of memory• Range from 1.7E-308 to 1.7E+308• Long double occupy 10 bytes of memory• Range from 3.4E-4932 to 3.4E+4932

Floating Pointfloat double long double

popo

Page 13: Data Type. A data type defines a set of values that a variable can store along with a set of operations that can be performed on that variable. Common

Data TypeType size (bytes) Range

char 1 127 to -128unsigned char 1 0 to 255int 2 32768 to -32767unsigned int 2 0 to 65535short int 2 32768 to -32767long int 4 2147483648 to - 2147483647unsigned long int 4 0 to 4294967295float 4 3.4E-38 to 3.4E+38double 8 1.7E-308 to 1.7E+308long double 10 3.4E-4932 to 3.4E+4932

popo

Page 14: Data Type. A data type defines a set of values that a variable can store along with a set of operations that can be performed on that variable. Common

Data Type• User Defined Data Type• Type Definition• Enumerated datatype• Structure• Union

User Defined Data typeType Definition

Enumerated datatypeStructure

Union

popo

Page 15: Data Type. A data type defines a set of values that a variable can store along with a set of operations that can be performed on that variable. Common

Data Type• User Defined Data Type• Type Definition• Allows user to define an identifier that would

represent an existing data type• This identifier can later used to declared

variables• syntax:--• Eg: typedef int integet;• integer a;

typedef type identifier

popo

Page 16: Data Type. A data type defines a set of values that a variable can store along with a set of operations that can be performed on that variable. Common

Data Type• User Defined Data Type• Enumerated • Allows user to declare variables can have one

value enclosed within braces.• Way of attaching name to numbers• syntax:--• Eg: enum sex{male,female};• Then value of male=0 and female=1

enum identifier {value1, value2, …..};

popo

Page 17: Data Type. A data type defines a set of values that a variable can store along with a set of operations that can be performed on that variable. Common

Data Type• User Defined Data Type• Structure• A structure is a collection of one or more variables, possibly of

different types, grouped together under a single nameA structure is defined by the keyword struct followed by a set of

variables enclosed in braces.Consider the following structure to represent a person’s details.

struct Personnel { char name[100];

int age; double height; };

The variables name, age and height are called members of the structure type Personnel.

popo

Page 18: Data Type. A data type defines a set of values that a variable can store along with a set of operations that can be performed on that variable. Common

Data Type• User Defined Data Type• StructureThere are two ways to define variables of a particular structure

type.1. Declare them at the structure definition.

struct Personnel { char name[100]; int age; double height;

} p1, p2, p3; /* Define 3 variables */

2. Define the variables at some point after the structure definition.

struct Personnel p1, p2, p3; /* Define 3 variables */

popo

Page 19: Data Type. A data type defines a set of values that a variable can store along with a set of operations that can be performed on that variable. Common

Data Type• User Defined Data Type• Union• A union is a collection of one or more variables, possibly of different

types, grouped together under a single nameA union is defined by the keyword union followed by a set of

variables enclosed in braces.Consider the following union to represent a person’s details.

union Personnel { char name[100];

int age; double height; };

The variables name, age and height are called members of the union type Personnel.

popo

Page 20: Data Type. A data type defines a set of values that a variable can store along with a set of operations that can be performed on that variable. Common

Data Type• User Defined Data Type• unionThere are two ways to define variables of a particular union

type.1. Declare them at the union definition.

union Personnel { char name[100]; int age; double height;

} p1, p2, p3; /* Define 3 variables */

2. Define the variables at some point after the union definition.

union Personnel p1, p2, p3; /* Define 3 variables */

popo

Page 21: Data Type. A data type defines a set of values that a variable can store along with a set of operations that can be performed on that variable. Common

Data Type• Derived datatype• Array…• Functions…• Pointers…• Reference…

Derived datatype

ArrayFunctionPointers

Reference

popo

Page 22: Data Type. A data type defines a set of values that a variable can store along with a set of operations that can be performed on that variable. Common

Data Type• Empty data type• void

popo

Page 23: Data Type. A data type defines a set of values that a variable can store along with a set of operations that can be performed on that variable. Common

Escape SequenceEscape

Sequence Effect

\a Beep sound \b Backspace \f Formfeed (for printing) \n New line \r Carriage return \t Tab \v Vertical tab \\ Backslash \” “ sign \o Octal decimal \x Hexadecimal \O NULL

Escape sequence is used in the printf() function to do something tothe output.

popo