w1coding.comAll tutorials

C Arraysofstr

C lessons
  1. Environment Setup
  2. Introduction
  3. Variables
  4. Operators
  5. Condition
  6. Loops
  7. Functions
  8. Arrays
  9. Pointers
  10. Strings
  11. Struct
  12. File
  13. Memory
  14. Recursions
  15. Bitwise
  16. Directives
  17. Commandline
  18. Switch
  19. Enum
  20. Structp
  21. Arraysofstr
  22. Macros
  23. Pointer Arrays
  24. Linked
  25. Stack
  26. Queue
  27. Graph

C Array of Structs

You can create an array of structs to store multiple instances of a struct in one array.

Example

#include 

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

int main() {
    struct Person people[2] = {{"Alice", 30}, {"Bob", 25}};

    for (int i = 0; i < 2; i++) {
        printf("Name: %s, Age: %d\n", people[i].name, people[i].age);
    }

    return 0;
}
    

This program demonstrates how to create an array of Person structs and prints their details.