
struct): meaning and featuresunion): meaning and memory sharingenum): meaning and useBasic data types (int, float, char, etc.) store single values. But real-world entities (student, book, employee) have multiple attributes.
So we use user-defined types to group related data together and make programs:
struct): meaning and featuresA structure is a user-defined data type that groups variables of different data types under one name.
Key features:
.General steps:
Concept example:
struct Student { int roll; char grade; };Student s; s.roll = 10;In C++, you can write Student s; directly (no need for struct Student s; like in C).
Useful when storing multiple objects of same type. Example idea: store 50 students.
A structure can contain another structure.
Example: Student contains Address.
These ideas are important for data management and later OOP.
In C++:
struct and class are very similar.struct members are public by defaultclass members are private by defaultThis is a common 2–3 mark question.
union): meaning and memory sharingA union is a user-defined type where all members share the same memory location.
Access the complete note and unlock all topic-wise content
It's free and takes just 5 seconds
Download this note as PDF at no cost
If any AD appears on download click please wait for 30sec till it gets completed and then close it, you will be redirected to pdf/ppt notes page.
struct): meaning and featuresunion): meaning and memory sharingenum): meaning and useBasic data types (int, float, char, etc.) store single values. But real-world entities (student, book, employee) have multiple attributes.
So we use user-defined types to group related data together and make programs:
struct): meaning and featuresA structure is a user-defined data type that groups variables of different data types under one name.
Key features:
.General steps:
Concept example:
struct Student { int roll; char grade; };Student s; s.roll = 10;In C++, you can write Student s; directly (no need for struct Student s; like in C).
Useful when storing multiple objects of same type. Example idea: store 50 students.
A structure can contain another structure.
Example: Student contains Address.
These ideas are important for data management and later OOP.
In C++:
struct and class are very similar.struct members are public by defaultclass members are private by defaultThis is a common 2–3 mark question.
union): meaning and memory sharingA union is a user-defined type where all members share the same memory location.
Key points:
Unions are used when we want to save memory and we know only one field is used at a time.
So changing one union member may overwrite the others.
enum): meaning and useAn enum is a user-defined type consisting of a set of named integer constants.
Example idea:
enum Day {Mon, Tue, Wed, Thu, Fri, Sat, Sun};Uses:
typedef is used to create an alias (alternate name) for a data type.
Examples:
typedef unsigned long ulong;typedef struct Student Student; (common in C, less needed in C++)Benefit:
As programs grow, different libraries may define functions/variables with the same name.
A namespace is used to avoid naming conflicts by grouping names.
Example: std::cout belongs to std namespace.
Ways:
std::cout, std::cinusing namespace std; (convenient but may cause conflicts in big projects)using std::cout;Important operator:
:: is the scope resolution operator.. and -> (arrow is for pointer to structure/class).using namespace std; everywhere in large code (can cause name conflicts).Name conflict? → Put names in namespace → Access using :: → Avoid clashes
std:: uses scope resolution operator ::.Get instant access to notes, practice questions, and more benefits with our mobile app.
From this topic
A structure groups related fields of different data types. Example: struct Student{int roll; char grade;};
We create variable Student s; and access members using . like s.roll=10.
This helps represent real-world entities.
In C++, struct and class are similar, but:
So the main difference is default access control.
A structure (struct) is a user-defined data type used to group related variables of different data types under one name.
Key points:
.) operator for structure variables.Example (concept):
struct Student { int roll; char grade; };Student s; s.roll = 10;Student
├─ roll (int)
└─ grade (char)
Thus, structures improve readability and data organisation in programs.