What is structure? Create a structure rectangle with data members length and breadth.

This answer is restricted. Please login to view the answer of this question.

Login Now

A structure is a collection of variables under a single name. These variables can be of different types, and each has a name that is used to select it from the structure. The variables are called members of the structure. A structure is a convenient way of grouping general pieces of the related information together.

A structure can be defined as a new named type or user-defined data type, thus extending the number of available types. It can be our other structures, arrays, or pointers as some of its members.

The syntax of structure is

struct structure_name
    data_type member_variables1;
    data_type member_variables2;
    ...... .......
    data_type member_variablesn;

Once structure_name is declared as a new data type, the variable of that can be declared as

struct structure_name structure_variable;

Example: A program to assign values of length and breadth to the member of structure. Rectangle and to display on the screen.


struct Rectangle{
    int length;
    int breadth;

void main(){

    struct Rectangle r;
    r.length = 55;
    r.breadth = 30;

    printf("The length of rectangle is %d", r.length);
    printf("The breadth of rectangle is %d", r.breadth);

If you found any type of error on the answer then please mention on the comment or report an answer or submit your new answer.
Leave your Answer:

Click here to submit your answer.

  Loading . . .