সি প্রোগ্রামিং-এ কাঠামোর একটি বিন্যাস হল বিভিন্ন ডেটাটাইপ ভেরিয়েবলের একটি সংগ্রহ, যা একটি একক নামে একত্রিত করা হয়েছে।
গঠন ঘোষণার সাধারণ রূপ
কাঠামোগত ঘোষণা নিম্নরূপ -
struct tagname{
datatype member1;
datatype member2;
datatype member n;
}; এখানে, struct হল কীওয়ার্ড৷
৷ট্যাগনাম কাঠামোর নাম নির্দিষ্ট করে।
সদস্য1, সদস্য2 ডেটা আইটেমগুলি নির্দিষ্ট করে যা গঠন তৈরি করে।
উদাহরণ
নিম্নলিখিত উদাহরণটি সি প্রোগ্রামিং -
-এ একটি কাঠামোর মধ্যে অ্যারের ব্যবহার দেখায়struct book{
int pages;
char author [30];
float price;
}; উদাহরণ
নীচে একটি কাঠামোর মধ্যে একটি অ্যারের ব্যবহার প্রদর্শন করার জন্য C প্রোগ্রাম রয়েছে −
#include <stdio.h>
// Declaration of the structure candidate
struct candidate {
int roll_no;
char grade;
// Array within the structure
float marks[4];
};
// Function to displays the content of
// the structure variables
void display(struct candidate a1){
printf("Roll number : %d\n", a1.roll_no);
printf("Grade : %c\n", a1.grade);
printf("Marks secured:\n");
int i;
int len = sizeof(a1.marks) / sizeof(float);
// Accessing the contents of the
// array within the structure
for (i = 0; i < len; i++) {
printf("Subject %d : %.2f\n",
i + 1, a1.marks[i]);
}
}
// Driver Code
int main(){
// Initialize a structure
struct candidate A= { 1, 'A', { 98.5, 77, 89, 78.5 } };
// Function to display structure
display(A);
return 0;
} আউটপুট
যখন উপরের প্রোগ্রামটি কার্যকর করা হয়, তখন এটি নিম্নলিখিত ফলাফল তৈরি করে -
Roll number : 1 Grade : A Marks secured: Subject 1 : 98.50 Subject 2 : 77.00 Subject 3 : 89.00 Subject 4 : 78.50