diff --git a/inherit/main.c b/inherit/main.c index b794429..a6008b6 100644 --- a/inherit/main.c +++ b/inherit/main.c @@ -6,18 +6,24 @@ int main () { + + /* Create generic vehicle type */ typedef struct { int life; int magic; }Vehicle; + + /* Create car, which is a type of vehicle + * access vehicle vars by doing car.vehicle.var + */ typedef struct { Vehicle vehicle; char brand[10]; }Car; - + /* We create our first car */ Car myCar; myCar.vehicle.life = 5; myCar.vehicle.magic = 9; @@ -26,6 +32,8 @@ int main () printf("My car's life is: %d\n" "My car's magic is: %d\n" "My car's brand is: %s\n\n", myCar.vehicle.life, myCar.vehicle.magic, myCar.brand); + + /* We create another to show using thing same struct with different values */ Car herCar; herCar.vehicle.life = 8; herCar.vehicle.magic = 5; @@ -34,7 +42,9 @@ int main () printf("Her car's life is: %d\n" "Her car's magic is: %d\n" "Her car's brand is: %s\n\n", herCar.vehicle.life, herCar.vehicle.magic, herCar.brand); - + /* Here we duplicate herCar (let's say we have a lot of saturns with same stats + * But may at some later point lose or gain stats + * */ Car herCar2 = herCar;