struct [C++ Reference]
Keywords: keywords,struct
Date: 2009-06-15T13:19:21-0700

[[struct]]
C++ Reference
Translations of this page?:

- en
- br-pt
- cn
- fr
- it
- jp
- pl
- ru
- tr

## struct

Syntax:

        struct struct-name : inheritance-list {
          public-members-list;
        protected:
          protected-members-list;
        private:
          private-members-list;
        } object-list;

Structs are like `classes`, except that by default members of a struct are public rather than private. In C, structs can only contain data and are not permitted to have inheritance lists.

The object list is optional – structs may be defined without actually instantiating any new objects.

For example, the following code creates a new datatype called Date (which contains three integers) and also creates an instance of Date called today:

         struct Date {
           int day;
           int month;
           int year;
         } today;

         int main() {
            today.day = 4;
            today.month = 7;
            today.year = 1776;
         }

Related Topics: class, union

Edit this page • Old revisions
• • • Login • Index • Recent changes • RSS • cc •