A structure variable is useful only if you can put values into its members and read them back. This section covers the dot operator, initialisation in the declaration, structures inside structures, and what can and cannot be done with a structure as a whole.
The dot operator
Syntax
structure-variable.member-name
The dot operator (.), also called the member operator, selects one member. The result behaves exactly like an ordinary variable of the member’s type: s1.roll_no is an int, so it can be assigned, used in arithmetic, or read with scanf("%d", &s1.roll_no). A string member such as s1.name is an array, so it is read with %s and no &, and set with strcpy.
Initialising a structure
A structure can be initialised in its declaration with values in braces, listed in the order of the members:
Syntax
struct tag variable = { value1, value2, ... };
Members without a value are set to zero.
Since C99, members can be named: struct sale s = { .amt = 600.0f, .item = "toolkit" }; (a designated initialiser).
Nested structures
A member of a structure can itself be a structure. This is a nested structure. Inner members are reached with two dots: mysale.buyer.firm.
Assigning and comparing whole structures
Operation
Allowed?
How
Assignment
Yes
b = a; copies every member, including arrays inside
Comparison with == or !=
No
Compare the members one by one
Size
Yes
sizeof(struct tag) or sizeof variable
Why no ==? A structure may contain padding bytes with unpredictable contents, so a byte-by-byte comparison could report two equal records as different, and C does not generate a member-by-member comparison automatically.
Key takeaways
The dot operator selects a member: s1.roll_no.
Initialise with { ... } in member order; unlisted members become zero.
Nested structures use nested braces and chained dots.
= copies a whole structure; == is not allowed; sizeof may include padding.
Practice questions
Answer on paper first, then check. The explanation matters more than the letter you chose.
Question 6 · short answer
Declare a structure date with integer members day, month and year together with a variable today initialised to 15 August 2026, and write the statement that prints it as 15/8/2026.
Show worked answer
struct date { int day; int month; int year; } today = { 15, 8, 2026 }; declares the type and the variable in one statement, with the values assigned in member order. To print: printf("%d/%d/%d\n", today.day, today.month, today.year);, which outputs 15/8/2026.
MCA Online notes are made for reading on screen. Open https://mcastudy.online/mcs-201/structures-and-unions/accessing-and-initialising-structure-members/ to read this page.