DMCA.com Protection Status C Programming – Day 9 | Structures in C Explained for Beginners - ZAREEN TECH WAVE -Largest Tutorials Website For Freelancer ZAREEN TECH WAVE -Largest Tutorials Website For Freelancer

Header Ads

C Programming – Day 9 | Structures in C Explained for Beginners

STRUCTURES IN C

DAY - 9


Learn C Programming Day 9 with a detailed guide on structures in C. Understand how to declare, initialize, and access members of user-defined data types for efficient data organization in C programming.

✅ Let’s move to Day-9 — Structures in C 🚀


📍 Day-9 — Structures in C

Today we will learn:

✅ What is a structure?
✅ Declaring & defining structures
✅ Accessing structure members
✅ Array of structures
✅ Nested structures (basic)
✅ Task + Quiz


✅ 1️⃣ What is a Structure?

📌 A structure is a user-defined data type that can store multiple variables of different types together.

Example:

struct Student { char name[30]; int age; float marks; };

✅ 2️⃣ Declare & Access Structure Variables

#include <stdio.h> #include <string.h> struct Student { char name[30]; int age; float marks; }; int main() { struct Student s1; strcpy(s1.name, "Jahid"); s1.age = 20; s1.marks = 88.5; printf("Name: %s\nAge: %d\nMarks: %.2f", s1.name, s1.age, s1.marks); }

✅ 3️⃣ Array of Structures

struct Student s[2]; for(int i=0; i<2; i++){ scanf("%s %d %f", s[i].name, &s[i].age, &s[i].marks); } for(int i=0; i<2; i++){ printf("%s %d %.2f\n", s[i].name, s[i].age, s[i].marks); }

✅ 4️⃣ Nested Structures (Basic)

struct Date { int day, month, year; }; struct Student { char name[30]; struct Date dob; };

Access:

s1.dob.day = 15;

✅ Task-9

Write a program:

✔ Input name, age, marks for 3 students
✔ Store them using array of structures
✔ Print details of all students

Example Output:

Student 1: Name=Jahid Age=20 Marks=88.5 Student 2: Name=Rahim Age=19 Marks=92.0 Student 3: Name=Karim Age=21 Marks=79.5

📌 Hint: Use loop to input & print


📝 Quick Quiz — Day-9

Reply like: 1B, 2A, 3C

1️⃣ Structure can store:
A) Single type of data
B) Multiple types of data
C) Only integers

2️⃣ Member of structure is accessed using:
A) . (dot)
B) -> (arrow)
C) &

3️⃣ Array of structures → used for:
A) Single student
B) Single value
C) Multiple records


📌 Reminder:

Send your Task-9 Code and Day-9 Quiz Answers when ready!

Then we will proceed to Day-10: File Handling in C 💪




C Programming Day 9 introduces structures in C, explaining how to create and use user-defined data types to store related information. Learn structure declaration, initialization, and accessing members with examples for beginners.

No comments

Thank You For Visit My Website.
I Will Contact As Soon As Possible.

Theme images by 5ugarless. Powered by Blogger.