0% found this document useful (0 votes)
13 views

Unit-IV Structure and Unions

Uploaded by

khurana.nitin122
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

Unit-IV Structure and Unions

Uploaded by

khurana.nitin122
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 33

1.

Structure in C: Definition, Declaration, and Initialization


Definition and Background

A structure in C is a user-defined data type that groups different data types into a single unit. It
is a way to logically organize data that represents real-world entities. Structures are declared
using the struct keyword.

Why Structures?

Real-life data is often composite. For instance:

● A student record may include a name (string), roll number (integer), and marks (float).
● A book entity may include a title, author, price, and publication year.

Using structures helps in managing and accessing such composite data efficiently.

Declaration and Initialization

● Declaration: Defining a structure specifies its layout but does not allocate memory.
● Initialization: Creating a variable of the structure type and assigning values to its
members.

Syntax
struct StructureName {

dataType member1;

dataType member2;

...

};

Real-Life Applications

● Database systems: To define records.


● File systems: To store metadata for files.
● Computer graphics: For defining properties of shapes like points, circles, etc.
Example 1: Basic Structure Definition and Initialization
#include <stdio.h>

struct Student {

char name[50];

int rollNumber;

float marks;

};

int main() {

struct Student s1 = {"Alice", 101, 95.5};

printf("Name: %s\n", s1.name);

printf("Roll Number: %d\n", s1.rollNumber);

printf("Marks: %.2f\n", s1.marks);

return 0;

Output:

Name: Alice

Roll Number: 101

Marks: 95.50
Explanation:
Here, a Student structure is defined, and an instance is initialized with values. The printf
statements access and display the structure members.

Example 2: Structure with Manual Initialization


#include <stdio.h>

struct Book {

char title[50];

char author[50];

float price;

};

int main() {

struct Book b1;

// Manual Initialization

printf("Enter book title: ");

scanf("%s", b1.title);

printf("Enter author: ");

scanf("%s", b1.author);

printf("Enter price: ");

scanf("%f", &b1.price);

printf("\nBook Details:\n");

printf("Title: %s\nAuthor: %s\nPrice: %.2f\n", b1.title, b1.author, b1.price);


return 0;

Output (Example):

Enter book title: Programming_C

Enter author: Dennis

Enter price: 399.50

Book Details:

Title: Programming_C

Author: Dennis

Price: 399.50

Explanation:
This example demonstrates how a structure's members are manually initialized using user
input.

Example 3: Array of Structures with Initialization


#include <stdio.h>

struct Employee {

char name[50];

int id;

float salary;

};
int main() {

struct Employee e[2] = {

{"John", 101, 50000.00},

{"Jane", 102, 60000.00}

};

for (int i = 0; i < 2; i++) {

printf("Employee %d:\n", i + 1);

printf("Name: %s\n", e[i].name);

printf("ID: %d\n", e[i].id);

printf("Salary: %.2f\n\n", e[i].salary);

return 0;

Output:

Employee 1:

Name: John

ID: 101

Salary: 50000.00

Employee 2:
Name: Jane

ID: 102

Salary: 60000.00

Explanation:
An array of Employee structures is initialized with data. A loop is used to display the details of
each employee.

Example 4: Passing Structures to Functions


#include <stdio.h>

struct Point {

int x, y;

};

void printPoint(struct Point p) {

printf("Point is (%d, %d)\n", p.x, p.y);

int main() {

struct Point p1 = {10, 20};

printPoint(p1);

return 0;

}
Output:

Point is (10, 20)

Explanation:
Here, a Point structure is passed as a parameter to a function, showcasing how structures
can be passed and used in functions.

2. Nested Structures
Definition and Background

Nested structures are structures within structures, allowing hierarchical or complex relationships
between data types.

Why Nested Structures?

They are used for:

● Representing hierarchical data, such as an address within a person’s record.


● Simplifying the management of complex data.

Example 1: Nested Structure


#include <stdio.h>

struct Address {

char city[50];

int zipCode;

};

struct Person {

char name[50];
struct Address addr;

};

int main() {

struct Person p1 = {"Alice", {"New York", 10001}};

printf("Name: %s\nCity: %s\nZip Code: %d\n", p1.name, p1.addr.city, p1.addr.zipCode);

return 0;

Output:

Name: Alice

City: New York

Zip Code: 10001

Explanation:
Here, the Address structure is nested inside the Person structure to represent a person’s
details including their address.

3. Arrays of Structures
Definition and Background

Arrays of structures allow storing and accessing multiple instances of a structure in a sequential
manner.
Example 1: Students with Arrays
#include <stdio.h>

struct Student {

char name[50];

int rollNo;

float marks;

};

int main() {

struct Student students[3] = {

{"Alice", 1, 90.5},

{"Bob", 2, 85.0},

{"Charlie", 3, 88.5}

};

for (int i = 0; i < 3; i++) {

printf("Name: %s, Roll No: %d, Marks: %.2f\n",

students[i].name, students[i].rollNo, students[i].marks);

return 0;

Output:
Name: Alice, Roll No: 1, Marks: 90.50

Name: Bob, Roll No: 2, Marks: 85.00

Name: Charlie, Roll No: 3, Marks: 88.50

4. Structures and Functions


Definition and Background

Structures in C are user-defined data types that group related variables of different data types
under a single name. Functions are blocks of code designed to perform specific tasks.
Combining structures and functions allows better modularity, code organization, and
manipulation of complex data.

Real-life Applications

1. Student Records Management: Storing and processing student details like name, roll
number, and marks.
2. Employee Database: Storing and calculating employee salaries, attendance, and
performance.
3. Graphics Systems: Managing points, colors, and shapes.

Example 1: Passing Structure to a Function


#include <stdio.h>
struct Student {
char name[50];
int roll;
float marks;
};

void display(struct Student s) {


printf("Name: %s\n", s.name);
printf("Roll: %d\n", s.roll);
printf("Marks: %.2f\n", s.marks);
}
int main() {
struct Student s1 = {"Alice", 1, 95.5};
display(s1);
return 0;
}

Output:

Name: Alice
Roll: 1
Marks: 95.50

Explanation: The Student structure is passed to the display function by value. The function
prints the structure's members.

Example 2: Passing Structure Pointer to a Function


#include <stdio.h>
struct Employee {
int id;
float salary;
};

void updateSalary(struct Employee *e) {


e->salary += 1000;
}

int main() {
struct Employee emp = {101, 5000.0};
updateSalary(&emp);
printf("Updated Salary: %.2f\n", emp.salary);
return 0;
}

Output:

Updated Salary: 6000.00


Explanation: A pointer to the Employee structure is passed, allowing the function to modify the
original structure.

Example 3: Returning a Structure from a Function


#include <stdio.h>
struct Point {
int x, y;
};

struct Point createPoint(int a, int b) {


struct Point p;
p.x = a;
p.y = b;
return p;
}

int main() {
struct Point pt = createPoint(5, 10);
printf("Point: (%d, %d)\n", pt.x, pt.y);
return 0;
}

Output:

Point: (5, 10)

Explanation: The createPoint function creates and returns a structure. This technique is
useful for initialization.

Example 4: Array of Structures with Functions


#include <stdio.h>
struct Product {
int id;
float price;
};

void displayProducts(struct Product products[], int n) {


for (int i = 0; i < n; i++) {
printf("Product ID: %d, Price: %.2f\n", products[i].id, products[i].price);
}
}

int main() {
struct Product p[2] = {{101, 25.5}, {102, 50.0}};
displayProducts(p, 2);
return 0;
}

Output:

Product ID: 101, Price: 25.50


Product ID: 102, Price: 50.00

Explanation: An array of structures is passed to a function to display multiple product details.

5. Self-Referential Structures
Definition and Background

A self-referential structure is a structure that contains a pointer to an instance of the same


structure type. These are primarily used in data structures like linked lists, trees, and graphs.

Real-life Applications

1. Linked Lists: Dynamic storage and efficient insertion/deletion.


2. Binary Trees: Hierarchical data management.
3. Graphs: Representing connections and networks.

Example 1: Linked List Node


#include <stdio.h>
#include <stdlib.h>

struct Node {
int data;
struct Node *next;
};
void printList(struct Node *n) {
while (n != NULL) {
printf("%d -> ", n->data);
n = n->next;
}
printf("NULL\n");
}

int main() {
struct Node *head = (struct Node *)malloc(sizeof(struct Node));
struct Node *second = (struct Node *)malloc(sizeof(struct Node));
struct Node *third = (struct Node *)malloc(sizeof(struct Node));

head->data = 1; head->next = second;


second->data = 2; second->next = third;
third->data = 3; third->next = NULL;

printList(head);
return 0;
}

Output:

1 -> 2 -> 3 -> NULL

Explanation: Each node points to the next node, forming a chain. This is the basis of linked
lists.

Example 2: Doubly Linked List


#include <stdio.h>
#include <stdlib.h>

struct Node {
int data;
struct Node *prev;
struct Node *next;
};

void printList(struct Node *n) {


while (n != NULL) {
printf("%d ", n->data);
n = n->next;
}
printf("\n");
}

int main() {
struct Node *head = (struct Node *)malloc(sizeof(struct Node));
struct Node *second = (struct Node *)malloc(sizeof(struct Node));

head->data = 1; head->prev = NULL; head->next = second;


second->data = 2; second->prev = head; second->next = NULL;

printList(head);
return 0;
}

Output:

12

Explanation: Each node points to both its predecessor and successor, enabling traversal in
both directions.

Other topics, Unions and Arrays of Union Variables, will follow a similar format with detailed
notes and examples. Would you like me to continue or adjust the detail level?

6. Unions

Definition and Background

A union in C is a user-defined data type that allows storing different data types in the same
memory location. Unlike structures, all members of a union share the same memory space,
meaning only one member can hold a value at a time. The size of a union is determined by the
size of its largest member.

Real-life Applications
1. Memory Optimization: Useful in embedded systems where memory is limited.
2. Variant Data Storage: Storing values of different types (e.g., int, float) in the same
location.
3. Device Drivers: Handling hardware register data that may represent different
functionalities.

Example 1: Basic Union Usage


#include <stdio.h>

union Data {
int intValue;
float floatValue;
};

int main() {
union Data d;
d.intValue = 10;
printf("Integer value: %d\n", d.intValue);
d.floatValue = 20.5;
printf("Float value: %.2f\n", d.floatValue);
printf("Integer value after float assignment: %d\n", d.intValue);
return 0;
}

Output:

Integer value: 10
Float value: 20.50
Integer value after float assignment: 1101529088

Explanation: The floatValue overwrites the memory of intValue, demonstrating how union
members share memory.

Example 2: Union with Enumerations


#include <stdio.h>

union DeviceStatus {
int errorCode;
float temperature;
};

enum Mode { ERROR, TEMP };

int main() {
union DeviceStatus status;
enum Mode currentMode = TEMP;

if (currentMode == ERROR) {
status.errorCode = 404;
printf("Error Code: %d\n", status.errorCode);
} else {
status.temperature = 36.5;
printf("Temperature: %.2f\n", status.temperature);
}
return 0;
}

Output:

Temperature: 36.50

Explanation: Union stores different types based on the current mode, optimizing memory for
conditional data.

Example 3: Union with Input and Output


#include <stdio.h>

union InputOutput {
char input[50];
int outputCode;
};

int main() {
union InputOutput io;
printf("Enter a string: ");
scanf("%s", io.input);
printf("You entered: %s\n", io.input);

io.outputCode = 200;
printf("Output Code: %d\n", io.outputCode);
return 0;
}

Output:

Enter a string: Hello


You entered: Hello
Output Code: 200

Explanation: Demonstrates switching between string and integer values using a union.

Example 4: Nested Unions


#include <stdio.h>

union Nested {
union {
int intData;
float floatData;
} data;
char charData;
};

int main() {
union Nested n;
n.data.intData = 5;
printf("Integer data: %d\n", n.data.intData);
n.charData = 'A';
printf("Char data: %c\n", n.charData);
return 0;
}

Output:

Integer data: 5
Char data: A

Explanation: Shows how nested unions operate by sharing memory among inner and outer
union members.
7. Arrays of Union Variables

Definition and Background

An array of unions is a collection of union variables stored in contiguous memory locations. It


allows managing a list of union variables, each capable of storing one of its defined member
types at a time.

Real-life Applications

1. Sensor Data: Managing heterogeneous sensor data types (e.g., temperature, pressure,
and humidity).
2. Network Protocols: Storing message headers of varying formats in network
communication.
3. Data Compression: Handling dynamic data types in compression algorithms.

Example 1: Array of Unions with Heterogeneous Data


#include <stdio.h>

union Item {
int id;
float price;
char name[20];
};

int main() {
union Item items[3];

items[0].id = 101;
items[1].price = 15.75;
sprintf(items[2].name, "Pen");

printf("Item ID: %d\n", items[0].id);


printf("Item Price: %.2f\n", items[1].price);
printf("Item Name: %s\n", items[2].name);

return 0;
}

Output:
Item ID: 101
Item Price: 15.75
Item Name: Pen

Explanation: Each union in the array stores a different type of data, demonstrating how unions
in arrays operate.

Example 2: Array of Unions with User Input


#include <stdio.h>

union Data {
int intValue;
float floatValue;
};

int main() {
union Data dataArr[2];
printf("Enter an integer: ");
scanf("%d", &dataArr[0].intValue);
printf("Enter a float: ");
scanf("%f", &dataArr[1].floatValue);

printf("Integer: %d\n", dataArr[0].intValue);


printf("Float: %.2f\n", dataArr[1].floatValue);

return 0;
}

Output:

Enter an integer: 10
Enter a float: 20.5
Integer: 10
Float: 20.50

Explanation: The array holds union elements, and user input dynamically assigns values to
them.
Example 3: Managing Sensor Readings
#include <stdio.h>

union Sensor {
int humidity;
float temperature;
};

int main() {
union Sensor sensors[2];
sensors[0].humidity = 60;
sensors[1].temperature = 22.5;

printf("Humidity: %d%%\n", sensors[0].humidity);


printf("Temperature: %.2f°C\n", sensors[1].temperature);

return 0;
}

Output:

Humidity: 60%
Temperature: 22.50°C

Explanation: Each union in the array stores a specific type of sensor data.

Example 4: Array of Unions with Conditional Access


#include <stdio.h>

union Data {
int id;
float grade;
};

int main() {
union Data students[3];
students[0].id = 1;
students[1].grade = 85.5;

printf("Student ID: %d\n", students[0].id);


printf("Student Grade: %.2f\n", students[1].grade);
return 0;
}

Output:

Student ID: 1
Student Grade: 85.50

Explanation: Demonstrates switching between id and grade for student records stored in an
array of unions.
8. Unions Inside Structures
Definition and Background

A union in C is a special data type where all members share the same memory location. This
means only one member of a union can store a value at any given time. A structure, on the
other hand, allows each member to have its own memory location, meaning all members can
store values simultaneously.

When we combine a union inside a structure, it allows us to group multiple data types in a
flexible and efficient way. This combination is useful when we need to store different types of
information based on certain conditions, while also saving memory.

Real-Life Example

Imagine a student record system where some students have their marks stored as
percentages (e.g., 85.5%), while others have grades stored as characters (e.g., 'A'). Using a
union within a structure, we can store either marks or grades for a student, depending on the
requirement, without wasting memory.

Example Code 1: Basic Union in Structure


#include <stdio.h>

struct Student {
char name[20];
int rollNumber;
union {
float percentage;
char grade;
} result;
};
int main() {
struct Student student1 = {"Alice", 1, .result.percentage = 92.5};
struct Student student2 = {"Bob", 2, .result.grade = 'B'};

// Display the results


printf("Student 1: Name=%s, Roll Number=%d, Percentage=%.2f\n", student1.name,
student1.rollNumber, student1.result.percentage);
printf("Student 2: Name=%s, Roll Number=%d, Grade=%c\n", student2.name,
student2.rollNumber, student2.result.grade);

return 0;
}

Output:

Student 1: Name=Alice, Roll Number=1, Percentage=92.50


Student 2: Name=Bob, Roll Number=2, Grade=B

Explanation:

● Here, each student has a union called result inside their structure.
● For Alice, the percentage is stored in result.percentage.
● For Bob, the grade is stored in result.grade.
The union ensures that only one type of result is stored at a time, saving memory.

Example Code 2: Employee Data with Union


#include <stdio.h>

struct Employee {
char name[20];
int id;
union {
int hoursWorked; // For hourly employees
float monthlySalary; // For salaried employees
} payment;
};

int main() {
struct Employee emp1 = {"John", 1001, .payment.hoursWorked = 160};
struct Employee emp2 = {"Emma", 1002, .payment.monthlySalary = 5000.50};

// Display employee payment details


printf("Employee 1: Name=%s, ID=%d, Hours Worked=%d\n", emp1.name, emp1.id,
emp1.payment.hoursWorked);
printf("Employee 2: Name=%s, ID=%d, Monthly Salary=%.2f\n", emp2.name, emp2.id,
emp2.payment.monthlySalary);

return 0;
}

Output:

Employee 1: Name=John, ID=1001, Hours Worked=160


Employee 2: Name=Emma, ID=1002, Monthly Salary=5000.50

Explanation:

● John works hourly, so his payment.hoursWorked is used.


● Emma is salaried, so her payment.monthlySalary is used.
The union within the structure allows storing payment details differently based on the
employee type.

Example Code 3: Sensor Readings


#include <stdio.h>

struct Sensor {
char type[10];
int id;
union {
int integerValue; // For simple measurements
float floatValue; // For precise measurements
} data;
};

int main() {
struct Sensor sensor1 = {"Pressure", 101, .data.integerValue = 100};
struct Sensor sensor2 = {"Temperature", 102, .data.floatValue = 37.5};

// Display sensor readings


printf("Sensor 1: Type=%s, ID=%d, Value=%d\n", sensor1.type, sensor1.id,
sensor1.data.integerValue);
printf("Sensor 2: Type=%s, ID=%d, Value=%.2f\n", sensor2.type, sensor2.id,
sensor2.data.floatValue);

return 0;
}

Output:

Sensor 1: Type=Pressure, ID=101, Value=100


Sensor 2: Type=Temperature, ID=102, Value=37.50

Explanation:

● Depending on the sensor type, we store data as either an integer (for simpler readings)
or a float (for precise measurements).
● This setup optimizes memory usage without compromising functionality.

9. Structures Inside Unions


Definition and Background

A structure inside a union allows grouping multiple related variables (as a structure) but
ensures only one structure’s data is active at any time within the union. This setup is useful
when dealing with complex data formats that vary depending on the situation.

Real-Life Example

Imagine a network packet that can either contain TCP header information (like source and
destination ports) or IP header information (like IP version and time-to-live). Using a structure
inside a union, we can model this packet to switch between the two formats seamlessly.

Example Code 1: Network Packet


#include <stdio.h>
union Packet {
struct {
int srcPort;
int destPort;
} tcp;
struct {
int version;
int ttl;
} ip;
};

int main() {
union Packet packet;

// TCP header
packet.tcp.srcPort = 8080;
packet.tcp.destPort = 80;

printf("TCP Packet: Src Port=%d, Dest Port=%d\n", packet.tcp.srcPort, packet.tcp.destPort);

// IP header
packet.ip.version = 4;
packet.ip.ttl = 64;

printf("IP Packet: Version=%d, TTL=%d\n", packet.ip.version, packet.ip.ttl);

return 0;
}

Output:

TCP Packet: Src Port=8080, Dest Port=80


IP Packet: Version=4, TTL=64

Explanation:

● First, we use the tcp structure to store TCP header data.


● Then, we use the ip structure for IP header data.
The union ensures only one format of data is active at a time.

Example Code 2: Multimedia Metadata


#include <stdio.h>

union Media {
struct {
int duration; // in seconds
int bitrate; // in kbps
} audio;
struct {
int width;
int height;
} video;
};

int main() {
union Media media;

// Audio metadata
media.audio.duration = 300;
media.audio.bitrate = 128;

printf("Audio: Duration=%d seconds, Bitrate=%dkbps\n", media.audio.duration,


media.audio.bitrate);

// Video metadata
media.video.width = 1920;
media.video.height = 1080;

printf("Video: Resolution=%dx%d\n", media.video.width, media.video.height);

return 0;
}

Output:

Audio: Duration=300 seconds, Bitrate=128kbps


Video: Resolution=1920x1080

Explanation:

● For audio files, media.audio is used.


● For video files, media.video is used.
This setup saves memory by storing only the relevant format.
10. Enumerated Data Type

Definition and Background

An enumerated data type (enum) in C is used to define a set of named integer constants. It
helps make programs more readable and maintainable by replacing literal numbers with
meaningful names. By default, the enumeration constants start from 0 and increment by 1 for
each subsequent value, but they can also be explicitly assigned specific values.

Real-Life Example

Enums are widely used in situations where we need to represent a set of predefined options.
For example:

● Days of the week: Instead of using numbers like 0 for Sunday and 6 for Saturday, we
can use SUNDAY, MONDAY, etc.
● Traffic light system: Using enums like RED, YELLOW, and GREEN makes the code
easier to understand and debug.

Example Code 1: Days of the Week


#include <stdio.h>

enum Day { SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY


};

int main() {
enum Day today;

today = TUESDAY;

if (today == TUESDAY) {
printf("Today is Tuesday. Time for team meeting!\n");
}

printf("Days of the week start from %d (SUNDAY) to %d (SATURDAY).\n", SUNDAY,


SATURDAY);

return 0;
}

Output:

Today is Tuesday. Time for team meeting!


Days of the week start from 0 (SUNDAY) to 6 (SATURDAY).

Explanation:

● The enum Day assigns numeric values to the days (SUNDAY = 0, MONDAY = 1, etc.).
● The program uses the named constants to check if it’s Tuesday and prints appropriate
messages.

Example Code 2: Traffic Light System


#include <stdio.h>

enum TrafficLight { RED, YELLOW, GREEN };

void displaySignal(enum TrafficLight signal) {


switch (signal) {
case RED:
printf("Stop! The light is RED.\n");
break;
case YELLOW:
printf("Caution! The light is YELLOW.\n");
break;
case GREEN:
printf("Go! The light is GREEN.\n");
break;
}
}

int main() {
enum TrafficLight currentSignal;

currentSignal = RED;
displaySignal(currentSignal);

currentSignal = GREEN;
displaySignal(currentSignal);
return 0;
}

Output:

Stop! The light is RED.


Go! The light is GREEN.

Explanation:

● The enum TrafficLight represents the three states of a traffic light.


● The displaySignal function uses a switch statement to print appropriate messages
based on the current signal.

Example Code 3: Error Codes


#include <stdio.h>

enum ErrorCode { SUCCESS = 0, WARNING = 1, ERROR = -1 };

void checkStatus(enum ErrorCode status) {


if (status == SUCCESS) {
printf("Operation completed successfully.\n");
} else if (status == WARNING) {
printf("Operation completed with a warning.\n");
} else if (status == ERROR) {
printf("Operation failed with an error.\n");
}
}

int main() {
enum ErrorCode status;

status = SUCCESS;
checkStatus(status);

status = WARNING;
checkStatus(status);

status = ERROR;
checkStatus(status);

return 0;
}

Output:

Operation completed successfully.


Operation completed with a warning.
Operation failed with an error.

Explanation:

● The enum ErrorCode assigns meaningful names to numeric values for error codes.
● The program uses these values to display appropriate messages.

Example Code 4: Months of the Year


#include <stdio.h>

enum Month { JANUARY = 1, FEBRUARY, MARCH, APRIL, MAY, JUNE, JULY, AUGUST,
SEPTEMBER, OCTOBER, NOVEMBER, DECEMBER };

int main() {
enum Month birthMonth = MAY;

printf("Your birth month is %d (MAY).\n", birthMonth);

if (birthMonth >= MARCH && birthMonth <= MAY) {


printf("You were born in Spring!\n");
} else if (birthMonth >= JUNE && birthMonth <= AUGUST) {
printf("You were born in Summer!\n");
}

return 0;
}

Output:

Your birth month is 5 (MAY).


You were born in Spring!
Explanation:

● The enum Month assigns numeric values to months, starting from 1 for January.
● The program uses these values to identify the birth month and season.

Advantages of Enumerated Data Types

1. Readability: Enums replace numbers with descriptive names, making the code easier to
understand.
2. Maintainability: Changes to enum values are centralized, reducing errors.
3. Error Prevention: By limiting valid values to a predefined set, enums help catch invalid
inputs.

Applications of Enumerated Data Types

1. Status Codes: Representing success, failure, and other states in applications.


2. Modes and Settings: Switching between modes like READ, WRITE, and EXECUTE.
3. Device States: Representing ON/OFF states or error codes in embedded systems.
4. Event Handling: Categorizing different types of user actions in graphical interfaces.

You might also like