Struct
A struct (short for structure) is a data type available in C programming languages, such as C, C++, and C#. It is a user-defined data type that can store multiple related items. A struct variable is similar to a database record since it may contain multiple data types related to a single entity.
Below is an example of an article defined as a struct in the C programming language.
struct Article
{
int articleID;
char title[120];
char date[10];
char author[60];
char content[4000];
}
The above struct "Article" contains both integer and character array data types. It can be used to store all the information about an article in a single variable. Since structs group the data into a contiguous block of memory, only a single pointer is needed to access all the data of a specific article.
Structs are similar to classes used in object oriented programing languages, such as Objective C and C#. The primary difference between the two data structures is that structs are public while classes are private by default. That means struct variables can be accessed and modified by any function within the code, while classes may only be accessed by the function in which they are defined.