# Struct

> A simple type that groups a few named values, like x and y of a point.

**Field:** Software Development  
**Category:** Programming Paradigms  
**Also known as:** Structure (Programming), Record Type, Structs

## Think of it like

It is like a lunch box with set spots. One for the sandwich, one for the apple, one for the drink.

## Definition

A struct groups a few named values into one new type. A Point struct might hold x and y. It is like a simple class, often with data and few or no methods. C, C#, Go, Rust and Swift all have structs. In C#, Swift and Go, a struct is usually copied when you pass it, while a class object is shared.

## Example

A game keeps each bullet as a struct with x, y and speed. Thousands of them fit in memory and move fast.

## Example code

```go
type Point struct {
    X int
    Y int
}

p := Point{X: 3, Y: 4}
fmt.Println(p.X)
// 3
```

A Point struct holds two named numbers, read with a dot.

## Why it matters

Structs make small bits of data easy to pass around and name. In many languages they are also fast and light.

## Common mistake

Assuming a struct acts like a class object. In C# and Swift, a changed copy does not change the first one.

## Three principles

- **Named fields.** Values grouped under one name.
- **Mostly data.** Few or no methods.
- **Often copied.** Passed as a copy in many languages.

## Related terms

- [Class](https://learn.benibix.com/term/development/class)
- [Object (Programming)](https://learn.benibix.com/term/development/object)
- [Data Type](https://learn.benibix.com/term/development/data-type)
- [Tuple](https://learn.benibix.com/term/development/tuple)
- [Pass by Value](https://learn.benibix.com/term/development/pass-by-value)
- [Go](https://learn.benibix.com/term/development/go-language)

## Told apart from

- [Struct vs Class](https://learn.benibix.com/compare/struct-vs-class): A struct is a simple bundle of named values. In C#, Swift and Go it is copied when you pass it. A class object is shared, so a change shows everywhere.

![Three panels. Struct: one box named Point holding x and y together. Union type: a value that is either a string or a number, shown as two doors with or between them. Composition: a Car box that holds an Engine box and four Wheel boxes inside it.](https://learn.benibix.com/diagrams/dev7-data-shapes.svg)

---

Source: https://learn.benibix.com/term/development/struct
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-17
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
