
- C Programming Tutorial
- C - Home
- C - Overview
- C - Environment Setup
- C - Program Structure
- C - Basic Syntax
- C - Data Types
- C - Variables
- C - Constants
- C - Storage Classes
- C - Operators
- C - Decision Making
- C - Loops
- C - Functions
- C - Scope Rules
- C - Arrays
- C - Pointers
- C - Strings
- C - Structures
- C - Unions
- C - Bit Fields
- C - Typedef
- C - Input & Output
- C - File I/O
- C - Preprocessors
- C - Header Files
- C - Type Casting
- C - Error Handling
- C - Recursion
- C - Variable Arguments
- C - Memory Management
- C - Command Line Arguments
- C Programming useful Resources
- C - Questions & Answers
- C - Quick Guide
- C - Useful Resources
- C - Discussion
Structure declaration in C language
The structure is a collection of different datatype variables, grouped together under a single name. It is a heterogeneous collection of data items that share a common name.
Features of structure
It is possible to copy the contents of all structural elements of different data types to another structure variable of its type by using an assignment operator.
To handle complex datatypes, it is possible to create a structure within another structure, which is called nested structures.
It is possible to pass an entire structure, individual elements of structure, and address of structure to a function.
It is possible to create structure pointers.
The general form of structure declaration is as follows −
datatype member1; struct tagname{ datatype member2; datatype member n; };
Here,
struct is the keyword.
tagname specifies the name of a structure
member1, member2 specifies the data items that makeup structure.
For example,
struct book{ int pages; char author [30]; float price; };
Structure variables
There are three ways of declaring structure variables, which are as follows −
Type 1
struct book{ int pages; char author[30]; float price; }b;
Type 2
struct{ int pages; char author[30]; float price; }b;
Type 3
struct book{ int pages; char author[30]; float price; }; struct book b;
- Related Articles
- Explain the variable declaration, initialization and assignment in C language
- Explain variable declaration and rules of variables in C language
- What is union of structure in C language?
- Explain linear data structure queue in C language
- Declaring a structure with no members in C language
- Explain the accessing of structure variable in C language
- Structure of Human Language
- How to access the pointer to structure in C language?
- Write a structure in local scope program using C language
- Explain bit field in C language by using structure concept
- What is a structure at local scope in C language?
- Write an example program on structure using C language
- State the importance of C language and its general structure
- Explain top-down design and structure chart of function in C language
- Explain the dynamic memory allocation of pointer to structure in C language
