#include <stdio.h>
struct Car {
char brand[50];
char model[50];
int year;
};
int main() {
struct Car car1 = {"BMW", "X5", 1999};
struct Car car2 = {"Ford", "Mustang", 1969};
struct Car car3 = {"Toyota", "Corolla", 2011};
printf("%s %s %d\n", car1.brand, car1.model, car1.year);
printf("%s %s %d\n", car2.brand, car2.model, car2.year);
printf("%s %s %d\n", car3.brand, car3.model, car3.year);
return 0;
}
/*
BMW X5 1999
Ford Mustang 1969
Toyota Corolla 2011
*/
Here the struct only has 3 variables (car1, car2, car3). But if it had numerous cars, how could I make this same code (print all values) using a loop?
Cars or the members of aCar? If it's the latter, then it's not possible in C.Cars