structuresa structure is a user-defined data type


Structures

A structure is a user-defined data type, which may have different data types as its members. Creating a structure is a two-part process. First, a structure template is explained. This template gives a lot of information to the compiler. For instance, how it is kept in the memory? How many member variables are there in this composite data element? What are the types of its member variables? For data types such as int, float, double, char this information is built into the compiler. But for the user-defined data types like structures, it has to be given to the compiler. This is given in the definition of the structure template. This template makes a new data type. Variables of this new data type can then be declared and used like basic data types.

e.g.

                struct Student

                 {

                                int Rollno;

                                char Name[15];

                                int Marks[6];

                                float percent;

                };

The above example depicts structure called students with enclosed data variables. The keyword struct is used to explain a structure template. Student is a name or tag. The variables of this type can be declared as follows :

 

                struct Student s1,s2;

[or ]

In C++ you can even omit the struct tag and declare the variables as,

                Student s1 = ( 100, "Sanket" , 20,10,30,40,50,60, 35.0};

                Student s2,jack;

                Student *sptr = &s1;

                Student s[100];

 

Request for Solution File

Ask an Expert for Answer!!
C/C++ Programming: structuresa structure is a user-defined data type
Reference No:- TGS0309348

Expected delivery within 24 Hours