##### cppreference.com

##### Search

Create account

##### Namespaces

- Page
- Discussion

##### Variants

##### Views

- View
- Edit
- History

##### Actions

# c/language/struct

From cppreference.com
< c‎ | language

Compound types are types that can hold multiple data members.

### [edit] Syntax

`struct` name `{` ``} instance `;`
| This section is incomplete

### [edit] Explanation

| This section is incomplete

### [edit] Keywords

`struct`

### [edit] Example

Run this code

    #include <stdio.h>

    struct car {
    	char *make;
    	char *model;
    	int year;
    };

    int main()
    {
    	/* external definition */
    	struct car c;
    	c.make = "Nash";
    	c.model = "48 Sports Touring Car";
    	c.year = 1923;
    	printf("%d %s %s\n", c.year, c.make, c.model);

    	/* internal definition */
    	struct spaceship {
    		char *make;
    		char *model;
    		char *year;
    	} s;
    	s.make = "Incom Corporation";
    	s.model = "T-65 X-wing starfighter";
    	s.year = "128 ABY";
    	printf("%s %s %s\n", s.year, s.make, s.model);

    	return 0;
    }

Output:

    1923 Nash 48 Sports Touring Car
    128 ABY Incom Corporation T-65 X-wing starfighter

Retrieved from "http://en.cppreference.com/mwiki/index.php?title=c/language/struct&oldid=48941"
Category:

- Todo without reason