Run ❯
Get your
own
website
❯
Run Code
Ctrl+Alt+R
Change Orientation
Ctrl+Alt+O
Change Theme
Ctrl+Alt+D
Go to Spaces
Ctrl+Alt+P
#include
#include
#include
struct Car { char brand[50]; int year; }; int main() { struct Car *cars = (struct Car*) malloc(3 * sizeof(struct Car)); if (cars == NULL) { printf("Memory allocation failed.\n"); return 1; } // Fill the data strcpy(cars[0].brand, "Ford"); cars[0].year = 2015; strcpy(cars[1].brand, "BMW"); cars[1].year = 2018; strcpy(cars[2].brand, "Volvo"); cars[2].year = 2023; // Print the data for (int i = 0; i < 3; i++) { printf("%s - %d\n", cars[i].brand, cars[i].year); } free(cars); return 0; }
Ford - 2015
BMW - 2018
Volvo - 2023