SlideShare uma empresa Scribd logo
1 de 25
F2037 - PROGRAMMING
FUNDAMENTAL WITH C++
Unit 4.2 - Understand the use of structures
INDEX
 Objective
 Introduction to Structures

 Declare structure variable

 Assign and access values of structure variable

 Array of structure

 Write program using structures
OBJECTIVES
   At the end of this module, students should:
     Declare  and use structure variable
     Identify the difference between structures and array
     Use array in structure
INTRODUCTION
 Array can be used to store and process large
  amount of similar data.
 However, it is limited as does not allow to store
  and manipulate dissimilar data items.
 Structure can be used to store and manipulate
  dissimilar data items.
INTRODUCTION TO STRUCTURE
 Structure is a collection of related data items
  stored in one place and referenced under one
  name.
 Each data item do not have to be the same type.



    struct student
      {
      char id [5];
      char name [18];
      char gender[10];
      int age;
      };
INTRODUCTION TO STRUCTURE


Id
Name
Gender
age
STRUCTURE DECLARATION
 Used struct keyword
 The variable in a structure are called structure
  elements or members
 Syntax



    struct   <structure name>
    {
               <struct member>;
    };
STRUCTURE DECLARATION
EXERCISE
   Create a struct named car with structure
    member type and year
struct car
{
       char type[10];
       int year;
};
DECLARING STRUCTURE VARIABLE
   First method

                   struct student
                    {
                    char id [ 5 ];
                    char name [ 18 ];
                    char gender[10];
                    int age;
                    } stud_1, stud_2;   variable
DECLARING STRUCTURE VARIABLE
   Second method
                     struct student
                       {
                       char id [ 5 ];
                       char name [ 18 ];
                       char gender[10];
                       int age;

                       };                       variable


           struct   student   stud_1, stud_2;
ASSIGN & ACCESS THE STRUCTURE
   A structure element can be accessed and
    assigned a value by using the structure variable
    name, the dot operator and the element’s name.

   For example;
     stud_1.name  = “Miriam”;
     stud_1.age = 21;
EXAMPLE
#include<iostream>
using namespace std;


struct student
{
     char id[10];
     char name[25];
     int age;
};
void main()
{
     struct student stud1 = {"123","Ani",12};
     cout<<"Student id: "<<stud1.id<<endl;
     cout<<"Student name: "<<stud1.name<<endl;
     cout<<"Student age: "<<stud1.age<<endl;
}
#include<iostream>
using namespace std;


struct student
{
    char id[10];
    char name[25];
    int age;
}stud1={"123","Ani",12};


void main()
{
    cout<<"Student id: "<<stud1.id<<endl;
    cout<<"Student name: "<<stud1.name<<endl;
    cout<<"Student age: "<<stud1.age<<endl;
}
#include<iostream>
using namespace std;


struct student
{
    char id[10];
    char name[25];
    int age;
}stud1;
void main()
{
    cout<<"enter your id:";
    cin.getline(stud1.id,10);
    cout<<"enter your name:";
    cin.getline(stud1.name,25);
    cout<<"enter your age:";
    cin>>stud1.age;


    cout<<"nDisplay result"<<endl;
    cout<<"your id is:"<< stud1.id<<endl;
    cout<<"your name is:"<< stud1.name<<endl;
    cout<<"your age is:"<< stud1.age<<endl;
}
EXERCISE
 Write a program to declare a structure named
  parent with structure member name and age.
 Create two structure variable named father and
  mother . Assign these two variable with the value
  name of your father and mother and their age.
 Display all of these value
   Write a program to declare a structure named
    parent with structure member name and age.

    #include<iostream.h>
    struct parent{
         char name[25];
         int age;
    };
   Create two structure variable named father and
    mother . Assign these two variable with the value
    name of your father and mother and their age.
    #include<iostream.h>
    struct parent{
         char name[25];
         int age;
    };
    void main(){
    struct parent father={"Ngadengon", 73};
    struct parent mother={"Satirah", 66};
}
 Display all of these value
#include<iostream.h>
struct parent{
       char name[25];
       int age;
  };
  void main(){
  struct parent father={"Ngadengon", 73};
  struct parent mother={"Satirah", 66};
  cout<<"Father:"<<father.name<<" Age:"<<father.age;
   cout<<"nMother:"<<mother.name<<" Age:"<<mother.age;
}
ARRAY OF STRUCTURE

 struct student
   {
   char id [5];
   char name [18];
   char gender[10];
   int age;
   };

 struct student stud [2];
#include<iostream>
using namespace std;


struct student
{
    char id[10];
    char name[25];
    int age;
}stud1[2];
void main()
{
    for(int i=0;i<2;i++){
               cout<<"nenter your id:";
               cin>>stud1[i].id;
               cout<<"enter your name:";
               cin>>stud1[i].name;
               cout<<"enter your age:";
               cin>>stud1[i].age;
    }
    cout<<"nDisplay result"<<endl;
    for(int x=0;x<2;x++){
               cout<<"your id is:"<< stud1[x].id<<endl;
               cout<<"your name is:"<< stud1[x].name<<endl;
               cout<<"your age is:"<< stud1[x].age<<endl;
    }
}
SUMMARY
 struct is a reserved keyword
 Members of struct can also be functions,
  including constructors and destructors.
 Member of struct by default are public.

Mais conteúdo relacionado

Mais procurados

Lecture 3, c++(complete reference,herbet sheidt)chapter-13
Lecture 3, c++(complete reference,herbet sheidt)chapter-13Lecture 3, c++(complete reference,herbet sheidt)chapter-13
Lecture 3, c++(complete reference,herbet sheidt)chapter-13Abu Saleh
 
Programming Fundamentals Arrays and Strings
Programming Fundamentals   Arrays and Strings Programming Fundamentals   Arrays and Strings
Programming Fundamentals Arrays and Strings imtiazalijoono
 
Intro to Functional Programming
Intro to Functional ProgrammingIntro to Functional Programming
Intro to Functional ProgrammingHugo Firth
 
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 4 of 5 by...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 4 of 5 by...Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 4 of 5 by...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 4 of 5 by...ssuserd6b1fd
 
Core c sharp and .net quick reference
Core c sharp and .net quick referenceCore c sharp and .net quick reference
Core c sharp and .net quick referenceArduino Aficionado
 
Uncommon Design Patterns
Uncommon Design PatternsUncommon Design Patterns
Uncommon Design PatternsStefano Fago
 
classes & objects in cpp overview
classes & objects in cpp overviewclasses & objects in cpp overview
classes & objects in cpp overviewgourav kottawar
 
TDC2016POA | Trilha .NET - CQRS e ES na prática com RavenDB
TDC2016POA | Trilha .NET - CQRS e ES na prática com RavenDBTDC2016POA | Trilha .NET - CQRS e ES na prática com RavenDB
TDC2016POA | Trilha .NET - CQRS e ES na prática com RavenDBtdc-globalcode
 
TDC2016POA | Trilha .NET - C# como você nunca viu: conceitos avançados de pro...
TDC2016POA | Trilha .NET - C# como você nunca viu: conceitos avançados de pro...TDC2016POA | Trilha .NET - C# como você nunca viu: conceitos avançados de pro...
TDC2016POA | Trilha .NET - C# como você nunca viu: conceitos avançados de pro...tdc-globalcode
 
C tech questions
C tech questionsC tech questions
C tech questionsvijay00791
 

Mais procurados (20)

Lecture 3, c++(complete reference,herbet sheidt)chapter-13
Lecture 3, c++(complete reference,herbet sheidt)chapter-13Lecture 3, c++(complete reference,herbet sheidt)chapter-13
Lecture 3, c++(complete reference,herbet sheidt)chapter-13
 
OOP v3
OOP v3OOP v3
OOP v3
 
Java cheatsheet
Java cheatsheetJava cheatsheet
Java cheatsheet
 
Programming Fundamentals Arrays and Strings
Programming Fundamentals   Arrays and Strings Programming Fundamentals   Arrays and Strings
Programming Fundamentals Arrays and Strings
 
PDBC
PDBCPDBC
PDBC
 
Lecture 12: Classes and Files
Lecture 12: Classes and FilesLecture 12: Classes and Files
Lecture 12: Classes and Files
 
Scala best practices
Scala best practicesScala best practices
Scala best practices
 
Intro to Functional Programming
Intro to Functional ProgrammingIntro to Functional Programming
Intro to Functional Programming
 
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 4 of 5 by...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 4 of 5 by...Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 4 of 5 by...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 4 of 5 by...
 
Core c sharp and .net quick reference
Core c sharp and .net quick referenceCore c sharp and .net quick reference
Core c sharp and .net quick reference
 
Array notes
Array notesArray notes
Array notes
 
Computer Programming- Lecture 4
Computer Programming- Lecture 4Computer Programming- Lecture 4
Computer Programming- Lecture 4
 
Uncommon Design Patterns
Uncommon Design PatternsUncommon Design Patterns
Uncommon Design Patterns
 
classes & objects in cpp overview
classes & objects in cpp overviewclasses & objects in cpp overview
classes & objects in cpp overview
 
TDC2016POA | Trilha .NET - CQRS e ES na prática com RavenDB
TDC2016POA | Trilha .NET - CQRS e ES na prática com RavenDBTDC2016POA | Trilha .NET - CQRS e ES na prática com RavenDB
TDC2016POA | Trilha .NET - CQRS e ES na prática com RavenDB
 
TDC2016POA | Trilha .NET - C# como você nunca viu: conceitos avançados de pro...
TDC2016POA | Trilha .NET - C# como você nunca viu: conceitos avançados de pro...TDC2016POA | Trilha .NET - C# como você nunca viu: conceitos avançados de pro...
TDC2016POA | Trilha .NET - C# como você nunca viu: conceitos avançados de pro...
 
Unit 3
Unit 3 Unit 3
Unit 3
 
Python : Dictionaries
Python : DictionariesPython : Dictionaries
Python : Dictionaries
 
Array
ArrayArray
Array
 
C tech questions
C tech questionsC tech questions
C tech questions
 

Destaque

Destaque (8)

Fp201 unit1 1
Fp201 unit1 1Fp201 unit1 1
Fp201 unit1 1
 
FP 201 Unit 2 - Part 3
FP 201 Unit 2 - Part 3FP 201 Unit 2 - Part 3
FP 201 Unit 2 - Part 3
 
FP 201 Unit 3
FP 201 Unit 3 FP 201 Unit 3
FP 201 Unit 3
 
FP 201 Unit 2 - Part 2
FP 201 Unit 2 - Part 2FP 201 Unit 2 - Part 2
FP 201 Unit 2 - Part 2
 
Unit 3
Unit 3Unit 3
Unit 3
 
Unit 1
Unit 1Unit 1
Unit 1
 
Unit 2
Unit 2Unit 2
Unit 2
 
Fp201 unit2 1
Fp201 unit2 1Fp201 unit2 1
Fp201 unit2 1
 

Semelhante a FP 201 - Unit4 Part 2

Stuctures in c++ in a sample way PPT
Stuctures in c++ in a sample way PPTStuctures in c++ in a sample way PPT
Stuctures in c++ in a sample way PPTNajam Khattak
 
CHAPTER -4-class and structure.pptx
CHAPTER -4-class and structure.pptxCHAPTER -4-class and structure.pptx
CHAPTER -4-class and structure.pptxGebruGetachew2
 
Structures in C.pptx
Structures in C.pptxStructures in C.pptx
Structures in C.pptxBoni Yeamin
 
Easy Understanding of Structure Union Typedef Enum in C Language.pdf
Easy Understanding of Structure Union Typedef Enum in C Language.pdfEasy Understanding of Structure Union Typedef Enum in C Language.pdf
Easy Understanding of Structure Union Typedef Enum in C Language.pdfsudhakargeruganti
 
Module 5-Structure and Union
Module 5-Structure and UnionModule 5-Structure and Union
Module 5-Structure and Unionnikshaikh786
 
Cs1123 12 structures
Cs1123 12 structuresCs1123 12 structures
Cs1123 12 structuresTAlha MAlik
 
Structure & Union in C++
Structure & Union in C++Structure & Union in C++
Structure & Union in C++Davinder Kaur
 
CONSTRUCTORS, DESTRUCTORS AND OPERATOR OVERLOADING.pptx
CONSTRUCTORS, DESTRUCTORS AND OPERATOR OVERLOADING.pptxCONSTRUCTORS, DESTRUCTORS AND OPERATOR OVERLOADING.pptx
CONSTRUCTORS, DESTRUCTORS AND OPERATOR OVERLOADING.pptxDeepasCSE
 
Basic of Structure,Structure members,Accessing Structure member,Nested Struct...
Basic of Structure,Structure members,Accessing Structure member,Nested Struct...Basic of Structure,Structure members,Accessing Structure member,Nested Struct...
Basic of Structure,Structure members,Accessing Structure member,Nested Struct...Smit Shah
 
VIT351 Software Development VI Unit4
VIT351 Software Development VI Unit4VIT351 Software Development VI Unit4
VIT351 Software Development VI Unit4YOGESH SINGH
 

Semelhante a FP 201 - Unit4 Part 2 (20)

Stuctures in c++ in a sample way PPT
Stuctures in c++ in a sample way PPTStuctures in c++ in a sample way PPT
Stuctures in c++ in a sample way PPT
 
C structures
C structuresC structures
C structures
 
Ch7 structures
Ch7 structuresCh7 structures
Ch7 structures
 
CHAPTER -4-class and structure.pptx
CHAPTER -4-class and structure.pptxCHAPTER -4-class and structure.pptx
CHAPTER -4-class and structure.pptx
 
12Structures.pptx
12Structures.pptx12Structures.pptx
12Structures.pptx
 
13. structure
13. structure13. structure
13. structure
 
Structures
StructuresStructures
Structures
 
Structures in C.pptx
Structures in C.pptxStructures in C.pptx
Structures in C.pptx
 
Easy Understanding of Structure Union Typedef Enum in C Language.pdf
Easy Understanding of Structure Union Typedef Enum in C Language.pdfEasy Understanding of Structure Union Typedef Enum in C Language.pdf
Easy Understanding of Structure Union Typedef Enum in C Language.pdf
 
Module 5-Structure and Union
Module 5-Structure and UnionModule 5-Structure and Union
Module 5-Structure and Union
 
Structures and Unions
Structures and UnionsStructures and Unions
Structures and Unions
 
Cs1123 12 structures
Cs1123 12 structuresCs1123 12 structures
Cs1123 12 structures
 
Structure & Union in C++
Structure & Union in C++Structure & Union in C++
Structure & Union in C++
 
CONSTRUCTORS, DESTRUCTORS AND OPERATOR OVERLOADING.pptx
CONSTRUCTORS, DESTRUCTORS AND OPERATOR OVERLOADING.pptxCONSTRUCTORS, DESTRUCTORS AND OPERATOR OVERLOADING.pptx
CONSTRUCTORS, DESTRUCTORS AND OPERATOR OVERLOADING.pptx
 
Structure.pptx
Structure.pptxStructure.pptx
Structure.pptx
 
Ocs752 unit 5
Ocs752   unit 5Ocs752   unit 5
Ocs752 unit 5
 
Basic of Structure,Structure members,Accessing Structure member,Nested Struct...
Basic of Structure,Structure members,Accessing Structure member,Nested Struct...Basic of Structure,Structure members,Accessing Structure member,Nested Struct...
Basic of Structure,Structure members,Accessing Structure member,Nested Struct...
 
VIT351 Software Development VI Unit4
VIT351 Software Development VI Unit4VIT351 Software Development VI Unit4
VIT351 Software Development VI Unit4
 
CP Handout#10
CP Handout#10CP Handout#10
CP Handout#10
 
Unit 5 (1)
Unit 5 (1)Unit 5 (1)
Unit 5 (1)
 

Mais de rohassanie

Course outline FP202 - Dis 2012
Course outline FP202 - Dis 2012Course outline FP202 - Dis 2012
Course outline FP202 - Dis 2012rohassanie
 
FP 202 - Chapter 5
FP 202 - Chapter 5FP 202 - Chapter 5
FP 202 - Chapter 5rohassanie
 
Chapter 3 part 2
Chapter 3 part 2Chapter 3 part 2
Chapter 3 part 2rohassanie
 
Chapter 3 part 1
Chapter 3 part 1Chapter 3 part 1
Chapter 3 part 1rohassanie
 
FP 202 Chapter 2 - Part 3
FP 202 Chapter 2 - Part 3FP 202 Chapter 2 - Part 3
FP 202 Chapter 2 - Part 3rohassanie
 
Chapter 2 (Part 2)
Chapter 2 (Part 2) Chapter 2 (Part 2)
Chapter 2 (Part 2) rohassanie
 
Labsheet 7 FP 201
Labsheet 7 FP 201Labsheet 7 FP 201
Labsheet 7 FP 201rohassanie
 
Labsheet 6 - FP 201
Labsheet 6 - FP 201Labsheet 6 - FP 201
Labsheet 6 - FP 201rohassanie
 
Jadual Waktu Sesi JUN 2012
Jadual Waktu Sesi JUN 2012Jadual Waktu Sesi JUN 2012
Jadual Waktu Sesi JUN 2012rohassanie
 
Chapter 2 part 1
Chapter 2 part 1Chapter 2 part 1
Chapter 2 part 1rohassanie
 
Labsheet2 stud
Labsheet2 studLabsheet2 stud
Labsheet2 studrohassanie
 
Labsheet1 stud
Labsheet1 studLabsheet1 stud
Labsheet1 studrohassanie
 
Chapter 1 part 3
Chapter 1 part 3Chapter 1 part 3
Chapter 1 part 3rohassanie
 
Chapter 1 part 2
Chapter 1 part 2Chapter 1 part 2
Chapter 1 part 2rohassanie
 
Chapter 1 part 1
Chapter 1 part 1Chapter 1 part 1
Chapter 1 part 1rohassanie
 
Introduction to C++
Introduction to C++Introduction to C++
Introduction to C++rohassanie
 

Mais de rohassanie (20)

Course outline FP202 - Dis 2012
Course outline FP202 - Dis 2012Course outline FP202 - Dis 2012
Course outline FP202 - Dis 2012
 
FP 202 - Chapter 5
FP 202 - Chapter 5FP 202 - Chapter 5
FP 202 - Chapter 5
 
Chapter 3 part 2
Chapter 3 part 2Chapter 3 part 2
Chapter 3 part 2
 
Chapter 3 part 1
Chapter 3 part 1Chapter 3 part 1
Chapter 3 part 1
 
FP 202 Chapter 2 - Part 3
FP 202 Chapter 2 - Part 3FP 202 Chapter 2 - Part 3
FP 202 Chapter 2 - Part 3
 
Lab ex 1
Lab ex 1Lab ex 1
Lab ex 1
 
Chapter 2 (Part 2)
Chapter 2 (Part 2) Chapter 2 (Part 2)
Chapter 2 (Part 2)
 
Labsheet 7 FP 201
Labsheet 7 FP 201Labsheet 7 FP 201
Labsheet 7 FP 201
 
Labsheet 6 - FP 201
Labsheet 6 - FP 201Labsheet 6 - FP 201
Labsheet 6 - FP 201
 
Jadual Waktu Sesi JUN 2012
Jadual Waktu Sesi JUN 2012Jadual Waktu Sesi JUN 2012
Jadual Waktu Sesi JUN 2012
 
Labsheet 5
Labsheet 5Labsheet 5
Labsheet 5
 
Labsheet 4
Labsheet 4Labsheet 4
Labsheet 4
 
Chapter 2 part 1
Chapter 2 part 1Chapter 2 part 1
Chapter 2 part 1
 
Labsheet_3
Labsheet_3Labsheet_3
Labsheet_3
 
Labsheet2 stud
Labsheet2 studLabsheet2 stud
Labsheet2 stud
 
Labsheet1 stud
Labsheet1 studLabsheet1 stud
Labsheet1 stud
 
Chapter 1 part 3
Chapter 1 part 3Chapter 1 part 3
Chapter 1 part 3
 
Chapter 1 part 2
Chapter 1 part 2Chapter 1 part 2
Chapter 1 part 2
 
Chapter 1 part 1
Chapter 1 part 1Chapter 1 part 1
Chapter 1 part 1
 
Introduction to C++
Introduction to C++Introduction to C++
Introduction to C++
 

FP 201 - Unit4 Part 2

  • 1. F2037 - PROGRAMMING FUNDAMENTAL WITH C++ Unit 4.2 - Understand the use of structures
  • 2. INDEX  Objective  Introduction to Structures  Declare structure variable  Assign and access values of structure variable  Array of structure  Write program using structures
  • 3. OBJECTIVES  At the end of this module, students should:  Declare and use structure variable  Identify the difference between structures and array  Use array in structure
  • 4. INTRODUCTION  Array can be used to store and process large amount of similar data.  However, it is limited as does not allow to store and manipulate dissimilar data items.  Structure can be used to store and manipulate dissimilar data items.
  • 5. INTRODUCTION TO STRUCTURE  Structure is a collection of related data items stored in one place and referenced under one name.  Each data item do not have to be the same type. struct student { char id [5]; char name [18]; char gender[10]; int age; };
  • 7. STRUCTURE DECLARATION  Used struct keyword  The variable in a structure are called structure elements or members  Syntax struct <structure name> { <struct member>; };
  • 9. EXERCISE  Create a struct named car with structure member type and year
  • 10. struct car { char type[10]; int year; };
  • 11. DECLARING STRUCTURE VARIABLE  First method struct student { char id [ 5 ]; char name [ 18 ]; char gender[10]; int age; } stud_1, stud_2; variable
  • 12. DECLARING STRUCTURE VARIABLE  Second method struct student { char id [ 5 ]; char name [ 18 ]; char gender[10]; int age; }; variable struct student stud_1, stud_2;
  • 13. ASSIGN & ACCESS THE STRUCTURE  A structure element can be accessed and assigned a value by using the structure variable name, the dot operator and the element’s name.  For example;  stud_1.name = “Miriam”;  stud_1.age = 21;
  • 14. EXAMPLE #include<iostream> using namespace std; struct student { char id[10]; char name[25]; int age; }; void main() { struct student stud1 = {"123","Ani",12}; cout<<"Student id: "<<stud1.id<<endl; cout<<"Student name: "<<stud1.name<<endl; cout<<"Student age: "<<stud1.age<<endl; }
  • 15. #include<iostream> using namespace std; struct student { char id[10]; char name[25]; int age; }stud1={"123","Ani",12}; void main() { cout<<"Student id: "<<stud1.id<<endl; cout<<"Student name: "<<stud1.name<<endl; cout<<"Student age: "<<stud1.age<<endl; }
  • 16.
  • 17. #include<iostream> using namespace std; struct student { char id[10]; char name[25]; int age; }stud1; void main() { cout<<"enter your id:"; cin.getline(stud1.id,10); cout<<"enter your name:"; cin.getline(stud1.name,25); cout<<"enter your age:"; cin>>stud1.age; cout<<"nDisplay result"<<endl; cout<<"your id is:"<< stud1.id<<endl; cout<<"your name is:"<< stud1.name<<endl; cout<<"your age is:"<< stud1.age<<endl; }
  • 18. EXERCISE  Write a program to declare a structure named parent with structure member name and age.  Create two structure variable named father and mother . Assign these two variable with the value name of your father and mother and their age.  Display all of these value
  • 19. Write a program to declare a structure named parent with structure member name and age. #include<iostream.h> struct parent{ char name[25]; int age; };
  • 20. Create two structure variable named father and mother . Assign these two variable with the value name of your father and mother and their age. #include<iostream.h> struct parent{ char name[25]; int age; }; void main(){ struct parent father={"Ngadengon", 73}; struct parent mother={"Satirah", 66}; }
  • 21.  Display all of these value #include<iostream.h> struct parent{ char name[25]; int age; }; void main(){ struct parent father={"Ngadengon", 73}; struct parent mother={"Satirah", 66}; cout<<"Father:"<<father.name<<" Age:"<<father.age; cout<<"nMother:"<<mother.name<<" Age:"<<mother.age; }
  • 22.
  • 23. ARRAY OF STRUCTURE struct student { char id [5]; char name [18]; char gender[10]; int age; }; struct student stud [2];
  • 24. #include<iostream> using namespace std; struct student { char id[10]; char name[25]; int age; }stud1[2]; void main() { for(int i=0;i<2;i++){ cout<<"nenter your id:"; cin>>stud1[i].id; cout<<"enter your name:"; cin>>stud1[i].name; cout<<"enter your age:"; cin>>stud1[i].age; } cout<<"nDisplay result"<<endl; for(int x=0;x<2;x++){ cout<<"your id is:"<< stud1[x].id<<endl; cout<<"your name is:"<< stud1[x].name<<endl; cout<<"your age is:"<< stud1[x].age<<endl; } }
  • 25. SUMMARY  struct is a reserved keyword  Members of struct can also be functions, including constructors and destructors.  Member of struct by default are public.