Start your programming journey with one of the most powerful and foundational languages — C. This comprehensive course is designed for absolute beginners as well as intermediate learners who want to build a solid understanding of programming using the C language. Whether you're preparing for college-level programming, cracking technical interviews, or planning to explore systems or embedded development, this course covers everything step-by-step. Through hands-on examples, real-world practice problems, and structured explanations, you’ll learn how to write clean and efficient C code — from your first printf() to advanced data structures and memory management.
In C, structures and unions are user-defined data types that allow grouping of different types of data under a single name. They help in organizing complex data, such as student records, product inventories, and more.
A structure is a collection of variables of different data types grouped together using the struct keyword.
struct Student {
int id;
char name[50];
float marks;
};
To declare and use a structure variable:
struct Student s1;
s1.id = 1;
strcpy(s1.name, "Anjali");
s1.marks = 89.5;
printf("Name: %s, Marks: %.2f", s1.name, s1.marks);
Let’s define and display details of a course listing on UdaanPath:
struct Course {
char title[50];
int duration; // in hours
float price;
};
int main() {
struct Course c1 = {"Intro to C Programming", 30, 299.99};
printf("Course: %s\nDuration: %d hrs\nPrice: ₹%.2f\n", c1.title, c1.duration, c1.price);
return 0;
}
You can store multiple student or product records using arrays of structures:
struct Student students[3];
for (int i = 0; i < 3; i++) {
printf("Enter ID and marks for student %d: ", i+1);
scanf("%d%f", &students[i].id, &students[i].marks);
}
void display(struct Student s) {
printf("%d %s %.2f", s.id, s.name, s.marks);
}
struct Student *ptr = &s1;
printf("%s", ptr->name);
struct Date {
int day, month, year;
};
struct Student {
int id;
struct Date dob;
};
A union is like a structure, but with a major difference: all members share the same memory space. This means only one member can hold a value at any time.
union Data {
int i;
float f;
char str[20];
};
Useful when you need to use the same memory space for multiple purposes.
| Structure | Union |
|---|---|
| Allocates separate memory for each member | Shares memory among all members |
| Can access all members at once | Can access only one member at a time |
| Larger size | Optimized size (max of all fields) |
In the next chapter, we’ll learn how to pass arrays, structures, and pointers to functions for advanced control and abstraction.