Structure
A Structure is a user-defined data type in C/C++. A structure creates a data type that can be used to group items of possibly different types into a single type.
Syntax
struct structName{
char varName[size];
int varName;
};
Example:
The below example demonstrates the use of structures in C++.
CPP
// C++ program to demonstrate // Structures in C++ #include <iostream> using namespace std; // declaring structure struct Point { int x, y; }; int main() { // Create an array of structures struct Point arr[10]; // Access array members arr[0].x = 10; arr[0].y = 20; cout << arr[0].x << ", " << arr[0].y; return 0; } |
10, 20
Explanation: The above demonstrates program demonstrates the use of structures by defining a structure named “Points” having x and y coordinates. It creates an array of these structures in the main function, sets their values, and prints them.
User Defined Data Types in C++
Data types are means to identify the type of data and associated operations of handling it. improve. In C++ datatypes are used to declare the variable. There are three types of data types:
- Pre-defined DataTypes
- Derived Data Types
- User-defined DataTypes
In this article, the User-Defined DataType is explained: