- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Structures in C
Structure is a user defined datatype. It is used to combine the different types of data into single type. It can have multiple members and structure variables. The keyword “struct” is used to define structures in C language. Structure members can be accessed by using dot(.) operator.
Here is the syntax of structures in C language,
struct structure_name { member definition; } structure_variables;
Here,
structure_name − Any name given to the structure.
member definition − Set of member variables.
structure_variable − This is the object of structure.
Here is an example of structures in C language,
Example
#include <stdio.h> #include <string.h> struct Data { int i; long int f; }data, data1; int main( ) { data.i = 28; printf("The value of i : %d
", (data.i)); printf( "Memory size occupied by data : %d\t%d", sizeof(data), sizeof(data1)); return 0; }
Output
The value of i : 28 Memory size occupied by data : 1616
In the above program, a structure Data is created with the objects of structure. The variable declared in structure is called in main() by using the object of structures.
struct Data { int i; long int f; }data, data1; int main( ) { data.i = 28; printf("The value of i : %d
", (data.i)); printf( "Memory size occupied by data : %d\t%d", sizeof(data), sizeof(data1)); }
- Related Articles
- Difference between C structures and C++ structures
- Inbuilt Data Structures in C#
- Classes vs Structures in C#
- Difference between Structures in C and C++
- What are nested structures in C language?
- Differentiate between array and structures in C
- Explain structures using typedef keyword in C language
- Explain the array of structures in C language
- What are pointers to structures in C language?
- What is an array of structures in C language?
- 2-3 Trees - Data Structures and Algorithms in C++
- Explain the concept of union of structures in C language
- C program to sort names in alphabetical order using structures
- C program to store inventory system using structures
- Which structures in human female are equivalent to the following structures in the human male?(a) testes (b) vas deferens (c) penis In each case say in what respect the structures are equivalent?

Advertisements