Skip to main content

Struct

// ------------------------------------
// Definition
// ------------------------------------

struct Struct_name {
some_type variable_name;
some_type variable_name;
...
some_type variable_name;
} struct_alias;

// ------------------------------------
// Declaration Example
// ------------------------------------
struct Person
{
char name[50];
int age;
};

// ------------------------------------
// Assignment
// ------------------------------------

struct Person some_person; // Either use "struct myStruct" or a type alias

strcpy(some_person.name, "my name"); // strcpy() from <string.h>
some_person.age = 30;

// ------------------------------------
// Others
// ------------------------------------

// You can also return a struct from a function
struct Person getSomeone(void)
{
// ...
}

More Info: