UdaanPath Logo UdaanPath

📖 Chapters

Data Structures and Algorithms in C  (DSA)

Data Structures and Algorithms in C (DSA)

Category: IT Fundamentals & Programming

This course is designed to help learners master the core concepts of Data Structures and Algorithms (DSA) using the C programming language. Starting from the basics and advancing to complex topics like graphs, dynamic programming, and memory optimization, this course …

Structures and Unions with Arrays

📘 Structures and Unions with Arrays

C language offers composite data types called structures and unions that allow grouping of different types of data under one name. These are especially useful when managing records like student profiles, product data, etc.

🏗️ What is a Structure?

A structure (struct) is a user-defined data type that groups variables of different data types under one name.

struct Student {
    int roll;
    char name[50];
    float marks;
};
  

📦 Declaring & Accessing Structure Variables

struct Student s1;
strcpy(s1.name, "Amit");
s1.roll = 101;
s1.marks = 87.5;
printf("Name: %s, Roll: %d, Marks: %.2f", s1.name, s1.roll, s1.marks);
  

🧑‍🎓 Array of Structures – Example (UdaanPath)

Suppose you're storing student data for a scholarship test on UdaanPath:

struct Student students[3];

for (int i = 0; i < 3; i++) {
    printf("Enter name, roll and marks for student %d: ", i+1);
    scanf("%s %d %f", students[i].name, &students[i].roll, &students[i].marks);
}
  

🔄 Passing Structure to Functions

void printStudent(struct Student s) {
    printf("Name: %s | Roll: %d | Marks: %.2f\n", s.name, s.roll, s.marks);
}
  

⚖️ Structure vs Union

Feature Structure Union
Memory Allocates memory for all members Shares memory (max size member)
Access All members accessible at once Only one member at a time
Use Case Used for grouped data Memory efficient alternatives

🔗 Union Example

union Data {
    int i;
    float f;
    char str[20];
};

union Data d;
d.i = 10;
printf("d.i = %d", d.i);
  

📚 Practice Tasks

  • Create an array of 5 employees with id, name, salary
  • Write a function to print student details using structures
  • Use union to store different sensor types (int, float, char)
  • Compare memory size of structure and union with sizeof()

✅ Summary

  • Structures group different data types in one unit
  • Unions share memory and are space efficient
  • Both are key for real-world modeling like records, packets, events

📤 Coming Next

In the next chapter, we’ll learn how to pass arrays, structures, and pointers to functions — enabling modular and efficient code structure.

ECHO Education Point  📚🎒

ECHO Education Point 📚🎒

ECHO Education Point proudly presents its Full Stack Development program 💻 – designed to launch your career in tech!

  • 🚀 Master both Front-End and Back-End technologies
  • 🧪 Includes 11 Mock Tests, 35 Mini Projects & 3 Website Builds
  • 🎯 Special training for job interviews & placement preparation

📍 Location: D-Mart Road, Meghdoot Nagar, Mandsaur
📞 Contact: 8269399715

Start your coding journey with expert instructor Vijay Jain (B.C.A., M.Sc., M.C.A.)
10 Days Free Demo Classes – Limited seats available!

#ECHO #FullStackDevelopment #MandsaurCoding