Structure


            Array and pointers are powerful tools to represent group of data
            items of same data type with a single name. How ev'r if we want to
            represent a group of data items of different data types with a single
            name, the array concept will not support. So 'C' language provides a
            data type named as STRUCTURES to do this task.Thus the structure is
            used to collect the different type data items.

            The structure will allocate the memory for the member,during
            execution time.The memory will allocate in separatly for each and
            every member or structure Variable.

            Syn:-
            +----
                        Defining:-
                        ========
                        struct tag-name
                        {
                                    <data-type> member-1;
                                    <data-type> member-2;
                                    .
                                    .
                                    .
                        };
            Ex:-
                        struct emp
                        {
                                    int enos;
                                    float sal;
                                    char name[30];
                        };

            After Defined the structure, Directly we can not able to access the
            member of the structure.If you need to access the members, you should
            create one structure variable.

            If you need to access the member of the structure,by using that
            variable name follwed by one period operator(.)then the       structure
            member.

            Declaring the Structure variable:-
            =================================

                        struct <tag-name> var1,var2,....;
            Access the member:
            -----------------
                        var-name.member-name;
            Initialization:-
            ---------------
                        struct <tag-name> var1={ values };
                        struct emp e={12,13.90,"sisi-cmtes"};


                                                typedef
                                                =======
            This statement is used to define a alias for existing data type. We
            can define a new data type based on the behaviour of existing data
            type.

            Syn:
            ---
                        typedef <data-type> alias;

            Once we defined the alias, then we can use the alias anywhere in the
            program.

            Typedefinition structure:-
            --------------------------

            The typedefinition structure is collection of different data types.
            It is just a creating for new data type.

            Syn:-
            ------
                        typedef struct
                        {
                                    <data-type>
                                    <data-type>
                                    ..
                                    ..
                        }structure-name;

No comments: