CSS Computer Science (Optional) — Paper-I, Section-A, Topic II subtopic. Grouping data under one name, and manipulating data at the bit level.

Structures (struct)

struct Student {
    char name[20];
    int age;
    float gpa;
};
struct Student s1 = {"Ali", 20, 3.8};
printf("%s", s1.name);       // dot operator to access members

Unions

union Data {
    int i;
    float f;
    char c;
};
union Data d;
d.i = 10;     // writing to i overwrites the same memory f and c would use

Struct vs Union

struct union
Memory per member Separate for each Shared (overlapping)
Total size Sum of all members (plus padding) Size of the largest member
Simultaneous access All members valid at once Only the most recently written member is valid

Enumerations (enum)

enum Day {SUN, MON, TUE, WED, THU, FRI, SAT};   // SUN=0, MON=1, ... by default
enum Day today = WED;   // today holds the integer value 3

Bit Manipulation Operators

Operator Name Effect
& AND 1 only if both bits are 1
OR
^ XOR 1 if bits differ
~ NOT Flips every bit (1's complement)
<< Left shift Shifts bits left; each shift multiplies by 2
>> Right shift Shifts bits right; each shift divides by 2 (for unsigned/positive values)