📖 Samacheer Kalvi · 11th TN - English Medium · Computer Science · Page 225definition

Structures · Part 2

Chapter 3: 4 · Computer Science

and frank),their members can be accessed directly. The syntax for that is using a dot (.) between the object name and the member name. For example, the elements of the structure Student can be accessed as follows: balu.rollno balu.age balu.weight frank.rollno frank.age frank.weight Chapter Page - - (Anonymous Structure Vs Named Structure) A structure without a name/tag is called anonymous structure. struct long rollno; int age; float weight; } student; The student can be referred as reference name to the above structure and the elements can be accessed like student.rollno, student.age and student.weight .

. . Initializing structure elements Values can be assigned to structure elements similar to assigning values to variables. Example balu.rollno= “702016”; balu.age= ; balu.weight= .

; Also, values can be assigned directly as similar to assigning values to Arrays. balu={702016, , . }; . .

Structure Assignment Structures can be assigned directly instead of assigning the values of elements individually. Example If Mahesh and Praveen are same age and same height and weight then the values of Mahesh can be copied to Praveen struct Student Structure assignment is possible only if both structure variables/ objects are same type. int age; float height, weight; }mahesh; The age of Mahesh is and the height and weights are . and .

respectively.The following statement will perform the assignment. mahesh = { , . , . }; praveen =mahesh; will assign the same age, height and weight to Praveen.

Chapter Page - - Examples: #include <iostream> using namespace std; struct Student int age; float height, weight; } mahesh; void main( ) cout<< “ Enter the age:”<<endl; cin>>mahesh.age; cout<< “Enter the height:”<<endl; cin>>mahesh.height; cout<< “Enter the weight:”<<endl; cin>>mahesh.weight; cout<< “The values entered for Age, height and weight are”<<endl; cout<<mahesh.age<< “\t”<<mahesh.height<< “\t”<<Mahesh. weight; Output: Enter the age: Enter the height: . Enter the weight: . The values entered for Age, height and weight are .

. The following C++ program reads student information through keyboard and displays the same • Structure is a user-defined which has the combination of data items with different data types • Structure is

Related topics

Have a question about this topic?

Get an AI answer grounded in your actual textbook — with the exact page reference.

Ask AI about this topic →