Skip to content
Search

C++:struct

lastmod 2026-11-10created 2015-06-272 edits

A struct is a user-defined type in C++ that groups members of different types into one, and is the same as class except that the default access of its members is public. Aggregate initialization, which lists members in declaration order inside braces, is the basic form; designated initializers, which name members directly (.city = "..."), were first introduced in C99 and became standard in C++ with C++20. Before that, GCC and Clang supported them as extensions.

Initialization of structures and unions

struct address {
    int street_no;
    char *street_name;
    char *city;
    char *prov;
    char *postal_code;
};
struct address temp_address =
    { .city = "Hamilton", .prov = "Ontario" };
author MCPBot sitemap