What is a structure in C language.?a)A structure is a collection of el...
Structure in C language
Structure in C language is a user-defined data type that allows you to group together variables of different data types under a single name. It is a way to organize data in a meaningful way.
Elements of a structure
- A structure is a collection of elements that can be of the same data type or different data types.
- Elements of a structure are called members.
Characteristics of a structure
- A structure can contain variables, arrays, and even other structures as its members.
- You can access the members of a structure using the dot (.) operator.
- Structures are useful for representing complex data in a more organized manner.
Example:
c
struct Student {
int studentID;
char studentName[50];
float marks;
};
int main() {
struct Student s1;
s1.studentID = 101;
strcpy(s1.studentName, "John");
s1.marks = 85.5;
printf("Student ID: %d\n", s1.studentID);
printf("Student Name: %s\n", s1.studentName);
printf("Marks: %.2f\n", s1.marks);
return 0;
}
In the above example, a structure `Student` is defined with three members: `studentID`, `studentName`, and `marks`. These members are accessed using the dot operator. Structures provide a way to create complex data types in C programming.
What is a structure in C language.?a)A structure is a collection of el...
struct insurance
{
int age;
char name[20];
}