Professional Documents
Culture Documents
Structure in C Programming
Structure in C Programming
com/ 2024-01-14
structure in C programming
In C, a structure is a user-defined data type that allows you to group together variables of different
data types under a single name. Each variable within a structure is called a member or a field.
Structures provide a way to organize and represent complex data in a more meaningful and coherent manner.
struct StructureName {
// Member 1
DataType1 Member1;
// Member 2
DataType2 Member2;
// ...
// Member N
DataTypeN MemberN;
};
You use the dot (.) operator to access members of a structure. The syntax is as follows:
structure_variable.member
#include <stdio.h>
1/3
18_structres.md https://embeddedforall.com/ 2024-01-14
int main() {
// Declare a variable of type 'struct Person'
struct Person person1;
return 0;
}
Output:
In this example:
Structure Definition:
struct Person {
char name[50];
int age;
float height;
};
This defines a structure named Person containing three members: name (an array of characters), age (an
integer), and height (a float).
2/3
18_structres.md https://embeddedforall.com/ 2024-01-14
Here, the program prompts the user to input values for the name, age, and height members of the person1
structure.
Finally, the program displays the information entered by the user using the structure members.
This example demonstrates how structures in C allow you to create a custom data type (struct Person) to
represent a person's information with multiple attributes. Structures are particularly useful when dealing with
entities that have various properties, making the code more organized and readable.
3/3