Structures.pdf - Structs A structure is a user defined data type which allows you to combine related data items of different kinds and manipulate it as

Structures.pdf - Structs A structure is a user defined data...

This preview shows page 1 - 2 out of 4 pages.

Structs 1 A structure is a user defined data type which allows you to combine related data items of different kinds and manipulate it as if it were one unit. Structures are used to represent a record. A record is a group of fields that are related to a specific thing. Suppose you want to keep track of the accounts in a bank. You might want to store the following attributes about each account record: Account Number Account Type Balance Defining a structure To define a structure, you must use the struct statement. The struct statement defines a new data type. It usually contains more than one member or field . The fields can have different types and different lengths. The format of the struct statement in C++ is: struct [type-name] { data-type identifier-name; data-type identifier-name; ... Data-type identifier-name; }; type-name is the name of the structure type. Within the braces {}, there is a list of fields. Each field has a data type and a valid identifier name. The statement ends with a semicolon For example, struct Account { int accNumber; char accType; double balance; }; The type name is Account .
Image of page 1
Image of page 2

You've reached the end of your free preview.

Want to read all 4 pages?

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

Stuck? We have tutors online 24/7 who can help you get unstuck.
A+ icon
Ask Expert Tutors You can ask You can ask You can ask (will expire )
Answers in as fast as 15 minutes