1/11
Flashcards covering key concepts related to structures in C, including definition, usage, and relationship to Object-Oriented Programming.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
Structures in C
Grouping related data under a single name.
Structures as collections of data
Collect related data into a single, meaningful structure; allows us to model problems in terms of problem-specific data types.
Bank account data structure
Name, account number, branch sort code, and balance.
Student data structure
Name, student ID number, school, and degree subject.
Single Responsibility Principle (SRP) in structure design
Structures should encapsulate a meaningful unit of data and be named accordingly; larger structures can be composed from other structures.
typedef
Defines a new data type based on a structure, allowing its use without the 'struct' keyword.
'.'
Access to structure fields using the variable.
'->'
Access to pointer-to-structure fields via the pointer.
Pass by value vs. Pass by reference
Pass by value creates a copy, safer but uses more memory; pass by reference modifies the original, more efficient for large structures.
Self-referential structure
The structure contains a pointer to its own type, commonly used in linked lists, trees, and graphs.
Data abstraction with C structures
Group related data into logical units; model real-world entities.
Structure Design Mirrors OO Design
Identify key attributes and behaviors, determine relationships, create appropriate interfaces (functions).