struct my_struct {
    /* data */
};
  

Think of structs like a class that is all data no methods. kinda like Java data classes

when to use structs or classes

EX:

  struct person {
	char* name;
	int age;
	float height;
};

int main(){
    char name[5] = "asdf";
	struct person p = {name,1,2}; // initialize a struct
    printf("%s\n", p.name);
}
  

Other ways to initialize structs

  struct person p;

char name[5] = "asdf";
p.name = name;
p.age = 1;
p.height = 2;
  

struct pointer syntax

  int main(){
    char name[5] = "asdf";
    
	struct person p = {name,0,0};
	struct person* p_ptr = &p;
	printf("%s\n", p_ptr->p);
}
  
Note:We use the `->` arrow syntax like in classes when struct is a pointer because all a class is is just a struct with some methods bundled in. This is the reason why places like java and python use `this` and `self`. They can be thought of as structs.

TODO: Explain how classes == structs