capypad
0 day streak
c / beginner
Snippet

Defining a Struct

A struct is a user-defined data type that allows grouping related variables of different types together.

snippet.c
c
1
2
3
4
5
6
struct Player {
int id;
float health;
};
 
struct Player p1 = {1, 100.0};
Breakdown
1
struct Player {
Defines a new template named 'Player'.
2
int id; float health;
Variables inside the struct are called members.
3
struct Player p1 =
Creates an actual instance of the Player struct.