defination of structure, union and record in DS


Ø  Structure –
·         Structure is user defined data type that can store related information.
·         Structure is collection of different data type.
·         Structure is declared using the keyword struct which followed by the structure name.
·         Syntax -

struct [structure name]
   {
       member definition;
       member definition;
       ...
       member definition;
   };

·         Do not forget to place a semicolon after the declaration of structure.
·         Example –

Struct student
{
Int roll_no;
Char name[20];
Char course[20];
Float fees;
};

·         Each variable declare with in a structure is called a member of the structure

Ø  Union –
·         A union is a special data type available in C that allows storing different data types in the same memory location.
·         You can define a union with many members, but only one member can contain a value at any given time.
·         Unions provide an efficient way of using the same memory location for multiple purpose.
·         Defining a Union: To define a union, you must use the union statement in the same way as you did while defining a structure.
·         The union statement defines a new data type with more than one member for your program. The format of the union statement is as follows:

    union [union name]
    {
       member definition;
       member definition;
       ...
       member definition;
    };

·         Example –
Union student
{
Int roll_no;
Char name[20];
Char course[20];
Float fees;
};

Ø  Records –also called struct or compound data. Records is a basic data structure, records is a collection of fields, possibly of different data types, typically in fixed number and sequence. The fields of a records may als be called member, particularly in object oriented programming.