What is Structure in C Tamil - linto.in
Structure in C Tamil, ஒன்றுக்கும் மேற்பட்ட, வெவ்வேறு விதமான data-type value-வை, ஒரே variable-லில் சேமிப்பதே structure என்று அழைக்கபடுகிறது. array definition-ஐ சற்று நினைவுபடுத்தி பாருங்கள். ஒன்றுக்கு மேற்பட்ட ஒரேவிதமான data வை ஒரே variable-லில் store செய்வது array. ஆனால் structure-ல் ஒரேமாதிரியாகவும் store செய்துகொள்ளலாம், வெவ்வேறு விதமான data-வையும் store செய்துகொள்ளலாம். இதை உருவாக்க struct என்ற keyword பயன்படுத்தபடுகிறது.
Structure
ஒன்றுக்கும் மேற்பட்ட, வெவ்வேறு விதமான data-type value-வை, ஒரே variable-லில் சேமிப்பதே structure என்று அழைக்கபடுகிறது. array definition-ஐ சற்று நினைவுபடுத்தி பாருங்கள். ஒன்றுக்கு மேற்பட்ட ஒரேவிதமான data வை ஒரே variable-லில் store செய்வது array. ஆனால் structure-ல் ஒரேமாதிரியாகவும் store செய்துகொள்ளலாம், வெவ்வேறு விதமான data-வையும் store செய்துகொள்ளலாம்.
இதை உருவாக்க struct என்ற keyword பயன்படுத்தபடுகிறது.
Syntax for create structure
struct structure_name{
int variable_name;
float variable_name;
char variable_name;
double variable_name;
.....etc,
};
// Example store a book information
struct book{
int pages;
char book_name[10];
char author[20];
float price;
};
Explanation
struct - keyword
book - structure name
pages, book_name,author,price these are all structure members.
Syntax structure variable
இரண்டு வழிகளில் structure variable-ஐ create செய்யலாம்.
// Example1
struct book b1,b2;
// Exmaple2
struct book{
int pages;
char book_name[10];
char author[20];
float price;
}b1,b2; // b1,b2 are structure variable
//பயன்படுத்தும் முறை
b1.pages,b1.book_name,b1.author,b1.price
Example
#include<stdio.h>
#include<conio.h>
struct student{
int id;
char name[20];
int mark1,mark2,mark3;
int total;
float avg;
};
int main(){
struct student b; // structure variable
printf("\nEnter the student details");
scanf("%d %s %d %d %d",&b.id,b.name, &b.mark1,&b.mark2,&b.mark3);
b.total=b.mark1+b.mark2+b.mark3;
b.avg=(float)b.total/3;
printf("\n The student details are:");
printf("\n %d %s %d %f", b.id, b.name, b.total, b.avg);
return 0;
}
Output:
1Priscilla
98
87
79
The student details are:
1 Priscilla 264 88.0000