Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Defining and using structures in C
#1
Structures are user-defined data types that allow you to group multiple variables of different data types under a single name.

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

int main() {
    struct Person p1;
    strcpy(p1.name, "John");
    p1.age = 30;
    p1.salary = 50000.0;
    printf("Name: %s, Age: %d, Salary: %.2f\n", p1.name, p1.age, p1.salary);
    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 structures in C Qomplainerz 0 232 07-25-2023, 01:10 PM
Last Post: Qomplainerz
  Declaring and defining functions in C Qomplainerz 0 292 07-25-2023, 11:01 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: 6 Guest(s)