struct က မတူတဲ့ data type များကို object တစ်ခုလို group ဖွဲ့ပေးတဲ့နည်းလမ်းပါ။ Student တစ်ယောက်မှာ name, age, score ရှိသလို data တွေကို တစ်စုတည်းထားချင်တဲ့အခါ အသုံးဝင်ပါတယ်။
c
#include <stdio.h>
struct Student {
char name[30];
int age;
float score;
};
int main() {
struct Student s1 = {"Sai", 20, 86.5};
printf("Name: %s
", s1.name);
printf("Age: %d
", s1.age);
printf("Score: %.1f", s1.score);
return 0;
}struct Student က custom data structure တစ်ခုဖန်တီးတာပါ။ s1.name, s1.age လို dot operator နဲ့ member value ကိုယူပါတယ်။
You should see
Name: Sai Age: 20 Score: 86.5Info
Real project မှာ product, user, order, book စတဲ့ related data တွေကို struct နဲ့ model လုပ်နိုင်ပါတယ်။