User Defined Data Types are those data types which are created in (C++) using the inbuilt keywords

struct or class. Structure similarly is a user defined composite type i.e it is composed of members or fields of different data types.

Structures are declared with the keyword struct. Definition of members are placed within the declaration. € The format of structure is like: struct <struct tag> //d tag name { member Definition; member Definition; : : member definition; }[one or more structure variables];
€

struct person { char name[20]; //type char int age; //type int }p1; //structurevariable

o

o

o

The structure tag name can be used to declare variable of structure type. If d tag name is given at the last with suppose a structure variable then no more variables can be defined of that type. Structure elements are the members of the structure and are referenced through dot(.) or the arrow(->) operator, generally used to access the structure variables. For example: cout<´enter your nameµ; gets(p1.name); A structure can also be assigned to a structure no compared that only if structures are of same type.

is a data structure which holds multiple values of the same data type. €Generally arrays have a very significant role in C++ language. For example in employment management database systems.

€Array

€Arrays

of structures can also be created easily. (As an array can obtain similar elements, the combination having structures within an array is called array of structures.)

struct abc //tag name// { int rollno; char name[21]; float marks[5]; //arrays in structures// }abc[10];

#include<iostream.h> #include<conio.h> #include<stdio.h> Struct addr { int houseno ; char area[26]; char city[21]; }; Struct emp { int empno; char name[31]; char desig[21]; float salary; addr address; } worker;

Emp sales_emp[10]; void main() { clrscr(); int eno, i; cout<<´enter the employee number whose information is to be givenµ<<´\nµ; cin>>eno; for ( i=0 ; i<10 ;i++) { cout<<´employee numberµ<<´\nµ; cin>>sales_emp[i].empno; cout<<´employee name<<´\nµ; gets(sales_emp[i].name); cout<<´employee·s addressµ<<´\nµ; cout<<´house numberµ; cin>>sales_emp[i].address.houseno;

Sign up to vote on this title
UsefulNot useful