w1coding.comAll tutorials

C Struct

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 Structs

A struct in C is a collection of variables of different data types grouped together under a single name.

Declaring and Using Structs

#include 

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

int main() {
    struct Person person1 = {"Alice", 30};
    printf("Name: %s\n", person1.name);
    printf("Age: %d\n", person1.age);
    return 0;
}
    

This program demonstrates the use of a struct to store a person's name and age, and then access those values.