IEO Level 2- English Olympiad (SOF) Class 9 Coaching Programs

⏳ 🎯 Online Tests (2 Tests [50 Questions Each]): NTA Pattern, Analytics & Explanations

Click Here to View & Get Complete Material

Rs. 200.00

3 Year Validity (Multiple Devices)

🎓 Study Material (303 Notes): 2024-2025 Syllabus

Click Here to View & Get Complete Material

Rs. 450.00

3 Year Validity (Multiple Devices)

🎯 250 MCQs (& PYQs) with Full Explanations (2024-2025 Exam)

Click Here to View & Get Complete Material

Rs. 200.00

3 Year Validity (Multiple Devices)

Structure: Structure Variable in Assignment Statements, Structure Within Structure and Initializing Nested Structure

Illustration: Structure: Structure Variable in Assignment Statements, Structure Within Structure and Initializing Nested Structure
Illustration: Structure: Structure Variable in Assignment Statements, Structure Within Structure and Initializing Nested Structure

Structure

Structure Variable in Assignment Statements

The statement

S3 = S2.

  • assigns the value of each member of S2 to the corresponding member of S3.
  • Since a large structure can have many members, such an assignment statement requires the compiler to do a considerable amount of work.
  • Note that one structure variable can be assigned to another only when they are of the same structure type, otherwise compiler will give an error.

Structure Within Structure

This is called nesting of structure. Consider the following program in which date field is a structure.

# include < iostream. h >

# include < stdio. h >

struct today

{

int month.

int date.

int year.

} ;

struct biodata

{

char name [20] .

today date _of_ birth.

char add [30] .

} ;

void main ()

{

biodata b.

cout ≪ “Enter name” .

gets (b. name) .

cout ≪ “Enter birth month” .

cin ≫ b. date _of _birth. month.

cout ≪ “Enter birth date” .

cin ≫ b. date _of _birth. date.

cout ≪ “Enter birth year” .

cin ≫ b. date _of _birth. year.

cout ≪ “Enter address” .

gets (b. adds) .

cout ≪ “Name” ≪ b. name ≪ “⧵n” .

cout ≪ “Month” ≪ b. date _of_ birth. month ≪ “⧵n” ;

cout ≪ “Date” ≪ b. date _of_ birth. date ≪ “⧵n” .

cout ≪ “Year” ≪ b. date _of _birth. year ≪ “⧵n” .

cout ≪ “Address” ≪ b. adds ≪ “⧵n” .

}

Accessing Nested Structure Members

As the structure is nested inside another, we must apply the dot operator twice to access the structure members:

cin ≫ b. date_ of_ birth. month.

Initializing Nested Structure

It is initialized at the time of declaration of structure variable.

For example:

biodata bd = { “MOHIT” , {3,21, 1991} , “Rohini” } .

The inner braces are required just to separate the values, although it is ignored by the compiler.