Struct

A struct, or structure, in C programming languages is a container that holds variables of different data types that can be accessed together. Structs are helpful because they can categorize and group related data. Structs occur in C programming languages, which include C# and C++.

To initiate and use a struct, first declare the struct and place an optional title (or tag) before it:

struct Title { } ;

Then place a semicolon at the end of the struct.

Structs contain variables, which identify the specific piece of data with which they’re paired within the struct. Some common variables in C programming include int, char, and float, which indicate the data type they store. For example, if one struct holds data about one particular customer in a business, the variable char might relate to the customer’s name, while int (integer) contains their specific customer ID number. The specific information that a variable stores is known as a value. Structs provide a method of grouping related (or perhaps unrelated) data in an organized format.

To access data in a struct, use a member operator (often a period) between the variable and the specific data member. You can also use a pointer to locate data stored in a struct. Pointers use the memory address of a variable, which has been programmed within the struct, to locate that variable’s corresponding data.






Jenna Phipps
Jenna Phipps
Jenna Phipps is a writer for Webopedia.com, Enterprise Storage Forum, and CIO Insight. She covers data storage systems and data management, information technology security, and enterprise software solutions.

Related Articles

Software

Table of contents What is Software? History of Software Software vs. Hardware Software vs. Hardware Comparison Chart What Types of Software Exist? Saas vs....

Email Address

What is an Email Address? An email address is a designation for an electronic mailbox that sends and receives messages, known as email, on a...

Information Technology (IT) Architect

The information technology architect applies IT resources to meet specific business requirements. The role requires a high degree of technical expertise as well as...

Built-In Function

A built-in function is a function that is already available in a programming language, application, or another tool that can be accessed by end...

Geotargeting

Geotargeting is a method of delivering data or content to users based on...

Agile Project Management

Agile project management enables business teams to approach their projects and tasks with...

Private 5G Network

A private 5G network is a private local area network (LAN) that utilizes...