Friday, August 19, 2011

Structure and Array

Array play very important role with structure. Structure has two types of view with array.
   a)    Array of structure
   b)    Array within structure
 
An Array of Structure:  An array of structure of one-dimensional and multi-dimensional are declared by only changing the structure variables from fundamental type to an array type with no change in the structure declaration.
The general syntax used for declaration of array of structure be as:
  For one- dimensional:    
        struct structure-tag
        {
          data-type-1 structure element-1 or member-1;
          data-type-2 structure element-2or member-2;
          …………..……………………………………….;
          data-type-N structure element-N or member-N;
        };
        main()
        {
         struct structure-tag variable-name[size];
         local declaration;
         executable statements;
      }

Array within Structure:
                    An array within structure of one-dimensional and multi-dimensional is declared by changing the structure elements or members from fundamental type to an array type.

The general syntax used for declaration of array within structure is as:
  For one- dimensional:    
        struct structure-tag
        {
          data-type-1 member-element 1;
          data-type-2 member-element[size] or array-member[size];
        }variable list;

For two- dimensional:    
        struct structure-tag
        {
          data-type-1 member-element 1;
          data-type-2 array-member[size] [size];
        }variable list;

Structures and functions:
                         Like simple variables and arrays, it is possible to pass entire structure as an argument to a function. A structure variable can be passed to a function either by value or by reference.
              In case of passing structure by value, a copy of the entire structure is passed to the called function. As the function operates on the copy of the structure, so any modification to the structure member within the called function are not reflected back to the original structure. In contrast to pass by value, passing structure by reference involves passing a reference of the original structure to the function. The function now can access the original structure through its reference instead of working with the copy of the structure and hence any modifications made to the member of structure within the called function are reflected back to the original structure.      

Previous Next Home
0 Comments
Comments

Leave a Comment

:)) ;)) ;;) :D ;) :p :(( :) :( :X =(( :-o :-/ :-* :| 8-} :)] ~x( :-t b-( :-L x( =))

Twitter Delicious Facebook Favorites More