Structured Data Types : Arrays and Structures.
Objectives :
•
•
•
•
•
to understand the meaning of structure datatypes and its availability in C++.
To appreciate the use and importance of Arrays in C++ to differentiate between the use and implementation of different types of Arrays
To use structures as User Defined data type to write programs.
To understand and use typedef
Structured Data types :
Students till now whatever data type we have used are just primitive data types like int , char , float , etc. All these datatypes are defined within the C++ compiler and that is why they are also called as primitive. We can define a length using int , a weight using float , a name using characters etc. but suppose I tell you “please define a fruit for me in program” ,then your mind starts wondering, as you can't define a fruit just with any one datatype as you did with length , weight etc.
A Fruit itself is a composite entity having following attributes : color : can be described with a name i.e. char [ ] taste : can be described with a name i.e. char[ ] season : can be described with int i.e. 1 for summer , 2 for winter … price : can be described as float ans so on...
This means that to describe a fruit we need to have a collection of data-types bundled togeather so that all the attributes of the fruit can be captured. This is true for any real world thing around you say student , mobile , plant etc. So when we bundle many primitive data types together to define a real world thing then it is known as derived data type or structured data type or User defined data types. In this chapter we would look onto two important structured data types , one is Array and the other one is Structure.
Sometimes we need to have variables in very large quantities , that too of same data type i.e. suppose we want 200 integer variables. In this situation will you declare 200 individual variables ? Absolutely not. This is because it will :
a) wastage of time as well time taking