What is the purpose of data structures in C and C++?

  • Context: C/C++ 
  • Thread starter Thread starter pairofstrings
  • Start date Start date
  • Tags Tags
    C++ Data Structures
Click For Summary

Discussion Overview

The discussion revolves around the purpose and applications of data structures in C and C++. Participants explore various types of data structures, their functionalities, and real-life applications, including their role in software development and object-oriented programming.

Discussion Character

  • Exploratory
  • Technical explanation
  • Conceptual clarification

Main Points Raised

  • One participant inquires about the usefulness of data structures in constructing menu items for software applications and requests examples of their real-life applications.
  • Another participant explains that in Windows, menus are defined in text resource files that resemble structures and are converted into binary resource files, which are part of the program's executable file.
  • A participant defines data structures as methods to store data, mentioning examples like arrays and binary trees.
  • Further elaboration is provided on data structures, specifically linked lists, detailing their components and how they function in terms of data storage and retrieval.
  • Another participant emphasizes that data structures reflect relationships between data bits, mentioning elementary data types and more complex structures like arrays and structs, and introduces the concept of object-oriented programming as a progression from basic data structures.

Areas of Agreement / Disagreement

Participants express various perspectives on the definition and application of data structures, with no consensus reached on specific examples or the best practices for their use. The discussion remains open-ended with multiple viewpoints presented.

Contextual Notes

Some participants reference specific programming concepts and structures without fully resolving the complexities or dependencies involved in their definitions and applications.

pairofstrings
Messages
411
Reaction score
7
What is data structures in C and C++ all about?
I heard that data structures are useful in constructing menu items of any software's menu bar. Is it true? Please tell me more examples of the applications of data structures in real life.
Thanks.
 
Technology news on Phys.org
In the case of Windows, menus are normally defined in text resource files (.rc) which look similar to structures and converted to binary resource files (.res) or a visual resource tool is used that works with the binary resource files (.res) which eventually become part of a programs image file (.exe).

Getting back to structures, a wiki link for a basic description of them:

http://en.wikipedia.org/wiki/Struct_(C_programming_language)
 
A data structure is just a way to store data, for example array, bin. tree, etc.
 
To elaborate, a data structure stores information and generally has methods associated with it to search for, insert and delete data. For example, a linked list is a collection of nodes that look like this (in C syntax)

Code:
typedef struct list {
    node *head;
    int count;
} list;

typedef struct node {
    void *data;
    node *next;
} node;

The first struct called "list" contains a pointer to the head of the list (the first node) and an integer variable to hold the number of nodes. The second struct is a node, which contains a pointer to the data (the void * could be any type of data) and another pointer to the next node (which could be NULL if there is only one). Each time you insert a node into the linked list, you point it to the next node. When you want to extract data from the list, you can use a loop and cycle through each node using the the "next" pointer until you find what you want. So you see, depending on your data structure you may need to write methods to perform these tasks (in a lot of cases, the language you use will include a library of data structures and methods that you can use).

There are many other data structures, and some are better for certain things. Some terms you may run into (some have been mentioned) include arrays, stacks, hash tables, trees, there are many varieties of each.
 
A data structure is, as Max Plank and Adyssa said, just a way to store data in a way that reflects the relationship of the bits of data to one another. "byte", "integer", and "real" are elementary data types. More complicated are array, collections of different bits of data of the samer type, and the "structure" or "struct" in which the various pieces of data can be of different types. A structure can even have arrays or structs as elements.

But hopefully, you will soon move on to "object oriented programming", the best thing since sliced bread! An "object", called a "class" in C++ or Java, includes both data types and functions that operate on that data. For example, if you were writing a program to handle personnel for a company, you might define an "object" data type that includes, as data, name, address, salary or hourly wage, hours worked and then functions that allow you to set or return each of those, calculate and print wage reports, etc., all encapsulated in the data type itself- so that it is easy to incorporate into many different programs.
 

Similar threads

Replies
86
Views
3K
  • · Replies 10 ·
Replies
10
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 133 ·
5
Replies
133
Views
13K
  • · Replies 7 ·
Replies
7
Views
1K
  • · Replies 11 ·
Replies
11
Views
2K
  • · Replies 35 ·
2
Replies
35
Views
4K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 13 ·
Replies
13
Views
5K