8.derived data types

5
Derived Data Types What you’ll learn: o What are derived data types o Structures o Unions o Enumerations

Upload: hardik-gupta

Post on 22-May-2015

57 views

Category:

Engineering


0 download

TRANSCRIPT

Page 1: 8.derived data types

Derived Data Types

What you’ll learn:

o What are derived data types

o Structures

o Unions

o Enumerations

Page 2: 8.derived data types

What are Derived Data types ?

These are composed of more than one type of data.

We have already covered array and strings.

More derived data types: Structures

Unions

Enumerations

Page 3: 8.derived data types

Structure

Structure can contain more than one type of data.

Syntax:

struct tag_name{

Data_type_1 variable_name;

…..

Data_type_n variable_name;

}

Struct tag_name variable_list; (Note: Variable list is of type struct)

Page 4: 8.derived data types

Union

Special data type that enables us to store different types of data in the same memory location, i.e. memory is shared between these variables.

Only one member occupies memory at a given time.

Efficient way of using same memory location.

Prevents memory fragmentation.

Page 5: 8.derived data types

Enumeration

Consists of a set of named integer constants.

Syntax:

enum tag_name{

……enum-list------

}