Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Nested structures in C
#1
Structures can be nested within each other.

struct Address {
    char city[50];
    char state[50];
};

struct Person {
    char name[50];
    int age;
    struct Address address;
};

int main() {
    struct Person p1;
    strcpy(p1.name, "John");
    p1.age = 30;
    strcpy(p1.address.city, "New York");
    strcpy(p1.address.state, "NY");
    printf("Name: %s, Age: %d, City: %s, State: %s\n", p1.name, p1.age, p1.address.city, p1.address.state);
    return 0;
}
Also follow me on Youtube for videos about video games:
https://www.youtube.com/channel/UCxfkGVU...2mQ/videos
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Nested multi-line comments in C Qomplainerz 0 264 07-26-2023, 07:27 AM
Last Post: Qomplainerz
  Defining and using structures in C Qomplainerz 0 275 07-25-2023, 11:43 AM
Last Post: Qomplainerz
  Looping structures in C (for, while, do-while) Qomplainerz 0 261 07-25-2023, 10:54 AM
Last Post: Qomplainerz

Forum Jump:


Users browsing this thread: 7 Guest(s)