SlideShare a Scribd company logo
1 of 11
Download to read offline
Lab # 13
DE-32 (A)
    DME
◦ To learn how to declare multidimensional array

◦ To learn how to declare 2D dynamic array using pointers

◦ To learn the use and syntax of the structures
   Arrays can have two or more dimensions. The two
    dimensional array is called a matrix. It can be declared
    as
        int std[no. of rows][no. of columns];
   Two loops are used to input values to the array
    elements. E.g.
        for(i=0; i<no. of rows; i++)
          for(j=0; j<no. of columns; j++)
           {
                 cin>>std[i][j];
            }
   Like input, two loops are used to display values of the
    array elements. E.g.
        for(i=0; i<no. of rows; i++)
          for(j=0; j<no. of columns; j++)
           {
                 cout<<std[i][j];
             }
   Two dimensional arrays can be initialized as;
        int std[3][2]={{1234,56}, {2356, 99}, {1586, 90}};
       int std[][2]={{1234,56}, {2356, 99}, {1586, 90}};
   Pointers in C++ can also be used to declare a 2D dynamic
    array in which you can specify the number of rows and
    columns at the runtime.
    First you have to declare a double pointer mean a pointer
    that point to a variable pointer then we allocate memory for
    the variable pointers of any size we want and at last we will
    go to each location of the pointers and allocate memory for
    variables of any size. This can be done as

    int **m;
    m = new int* [size]; //array of pointers
         for ( int i=0; i<size; i++)
                  m[i] = new int [size];
Lab 13
#include<iostream>
using namespace std;

void main()
{
   int size;
   cin>>size;
   int **num;
   num= new int*[size];
   for(int i=0;i<size;i++)
            num[i]=new int[size];

    for(int i=0;i<size;i++)
             for(int j=0;j<size;j++)
                           cin>>num[i][j];

    for(int i=0;i<size;i++)
    {
             for(int j=0;j<size;j++)
             {
                           cout<<num[i][j]<<'t';
             }
             cout<<endl;
    }
}
   A structure is a collection of simple variables that can be of different types and functions.
    The data items in a structure are called members of a structure. Structures are defined
    using ‘struct’ keyword followed by the user defined name for the structure e.g.

    struct name
    {
            int a; //data member
            float b; //data member
            string c; //data member
            void function(); //member function
    }; //definition of structure ends with a semi-colon

   After the definition of the structure you can declare objects of the structure just like you
    declare a variable. To access the data and function member of a structure dot operator is
    used e.g.
    void main()
    {
           name n1;
           n1.a = 10;
           n1.b = 2.3;
           n1.c = “Hello “; //storing value in a data member
           n1.function(); //calling member function
    }
struct name
{
          int a; //data member
          float b; //data member
          string c; //data member
          void function()
          {
                       cout<<"HELLO WORLD";
          }//member function
}n;

struct name
{
          int a; //data member
          float b; //data member
          string c; //data member
          void function()
          {
                       cout<<"HELLO WORLD";
          }//member function

};
struct name n;
struct name
{
       int a; //data member
       float b; //data member
       string c; //data member
       void function()
       {
                cout<<"HELLO WORLD";
       }//member function

};
struct name n={10,20.0,"Hello"};
struct book
{
string name;
float price;
int pages;
};
struct book b[100];

void main()
{
   int i;
   for(i=0;i<100;i++)
   {
           cin>>b[i].name>>b[i].price>>b[i].pages;
   }
   for(i=0;i<100;i++)
   {
           cout<<b[i].name<<b[i].price<<b[i].pages<<endl;
   }

}

More Related Content

What's hot

Program: Inheritance in Class - to find topper out of 10 students
Program: Inheritance in Class - to find topper out of 10 studentsProgram: Inheritance in Class - to find topper out of 10 students
Program: Inheritance in Class - to find topper out of 10 studentsSwarup Boro
 
Two dimensional array
Two dimensional arrayTwo dimensional array
Two dimensional arrayRajendran
 
Machine Learning Game Changer for IT - Maartens Lourens
Machine Learning Game Changer for IT - Maartens LourensMachine Learning Game Changer for IT - Maartens Lourens
Machine Learning Game Changer for IT - Maartens LourensOpenCredo
 
Array in c language
Array in c languageArray in c language
Array in c languagehome
 
Chapter27 polymorphism-virtual-function-abstract-class
Chapter27 polymorphism-virtual-function-abstract-classChapter27 polymorphism-virtual-function-abstract-class
Chapter27 polymorphism-virtual-function-abstract-classDeepak Singh
 
2013 11 CSharp Tutorial Struct and Class
2013 11 CSharp Tutorial Struct and Class2013 11 CSharp Tutorial Struct and Class
2013 11 CSharp Tutorial Struct and ClassHung-Wei Liu
 
Array in c language
Array in c language Array in c language
Array in c language umesh patil
 
C Programming : Arrays
C Programming : ArraysC Programming : Arrays
C Programming : ArraysGagan Deep
 
11 1. multi-dimensional array eng
11 1. multi-dimensional array eng11 1. multi-dimensional array eng
11 1. multi-dimensional array eng웅식 전
 
Dynamics allocation
Dynamics allocationDynamics allocation
Dynamics allocationKumar
 

What's hot (20)

Litebox
LiteboxLitebox
Litebox
 
Ooprc4 b
Ooprc4 bOoprc4 b
Ooprc4 b
 
Program: Inheritance in Class - to find topper out of 10 students
Program: Inheritance in Class - to find topper out of 10 studentsProgram: Inheritance in Class - to find topper out of 10 students
Program: Inheritance in Class - to find topper out of 10 students
 
Two dimensional array
Two dimensional arrayTwo dimensional array
Two dimensional array
 
Machine Learning Game Changer for IT - Maartens Lourens
Machine Learning Game Changer for IT - Maartens LourensMachine Learning Game Changer for IT - Maartens Lourens
Machine Learning Game Changer for IT - Maartens Lourens
 
Hash tables
Hash tablesHash tables
Hash tables
 
2- Dimensional Arrays
2- Dimensional Arrays2- Dimensional Arrays
2- Dimensional Arrays
 
Array in c language
Array in c languageArray in c language
Array in c language
 
Chapter27 polymorphism-virtual-function-abstract-class
Chapter27 polymorphism-virtual-function-abstract-classChapter27 polymorphism-virtual-function-abstract-class
Chapter27 polymorphism-virtual-function-abstract-class
 
2013 11 CSharp Tutorial Struct and Class
2013 11 CSharp Tutorial Struct and Class2013 11 CSharp Tutorial Struct and Class
2013 11 CSharp Tutorial Struct and Class
 
Array in c language
Array in c language Array in c language
Array in c language
 
2D arrays
2D arrays2D arrays
2D arrays
 
C Programming : Arrays
C Programming : ArraysC Programming : Arrays
C Programming : Arrays
 
COW
COWCOW
COW
 
Array BPK 2
Array BPK 2Array BPK 2
Array BPK 2
 
Structure in c sharp
Structure in c sharpStructure in c sharp
Structure in c sharp
 
11 1. multi-dimensional array eng
11 1. multi-dimensional array eng11 1. multi-dimensional array eng
11 1. multi-dimensional array eng
 
Dynamics allocation
Dynamics allocationDynamics allocation
Dynamics allocation
 
Funcd
FuncdFuncd
Funcd
 
Tut Constructor
Tut ConstructorTut Constructor
Tut Constructor
 

Similar to Lab 13

C++ Nested loops, matrix and fuctions.pdf
C++ Nested loops, matrix and fuctions.pdfC++ Nested loops, matrix and fuctions.pdf
C++ Nested loops, matrix and fuctions.pdfyamew16788
 
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
 
OOP-Lecture-05 (Constructor_Destructor).pptx
OOP-Lecture-05 (Constructor_Destructor).pptxOOP-Lecture-05 (Constructor_Destructor).pptx
OOP-Lecture-05 (Constructor_Destructor).pptxSirRafiLectures
 
Oop lec 3(structures)
Oop lec 3(structures)Oop lec 3(structures)
Oop lec 3(structures)Asfand Hassan
 
CHAPTER -4-class and structure.pptx
CHAPTER -4-class and structure.pptxCHAPTER -4-class and structure.pptx
CHAPTER -4-class and structure.pptxGebruGetachew2
 
Computer Programming -II (Lec. 10).pptx
Computer Programming -II (Lec. 10).pptxComputer Programming -II (Lec. 10).pptx
Computer Programming -II (Lec. 10).pptxSaurabhSharma783949
 
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
 
data structure and c programing concepts
data structure and c programing conceptsdata structure and c programing concepts
data structure and c programing conceptskavitham66441
 
Lecture 9_Classes.pptx
Lecture 9_Classes.pptxLecture 9_Classes.pptx
Lecture 9_Classes.pptxNelyJay
 
C++ Course - Lesson 3
C++ Course - Lesson 3C++ Course - Lesson 3
C++ Course - Lesson 3Mohamed Ahmed
 
Arrry structure Stacks in data structure
Arrry structure Stacks  in data structureArrry structure Stacks  in data structure
Arrry structure Stacks in data structurelodhran-hayat
 
booksoncprogramminglanguage-anintroductiontobeginnersbyarunumrao4-21101016591...
booksoncprogramminglanguage-anintroductiontobeginnersbyarunumrao4-21101016591...booksoncprogramminglanguage-anintroductiontobeginnersbyarunumrao4-21101016591...
booksoncprogramminglanguage-anintroductiontobeginnersbyarunumrao4-21101016591...GkhanGirgin3
 
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
 

Similar to Lab 13 (20)

C++ Nested loops, matrix and fuctions.pdf
C++ Nested loops, matrix and fuctions.pdfC++ Nested loops, matrix and fuctions.pdf
C++ Nested loops, matrix and fuctions.pdf
 
Chapter1.pptx
Chapter1.pptxChapter1.pptx
Chapter1.pptx
 
12Structures.pptx
12Structures.pptx12Structures.pptx
12Structures.pptx
 
Module 5-Structure and Union
Module 5-Structure and UnionModule 5-Structure and Union
Module 5-Structure and Union
 
Cs1123 12 structures
Cs1123 12 structuresCs1123 12 structures
Cs1123 12 structures
 
The STL
The STLThe STL
The STL
 
OOP-Lecture-05 (Constructor_Destructor).pptx
OOP-Lecture-05 (Constructor_Destructor).pptxOOP-Lecture-05 (Constructor_Destructor).pptx
OOP-Lecture-05 (Constructor_Destructor).pptx
 
Oop lec 3(structures)
Oop lec 3(structures)Oop lec 3(structures)
Oop lec 3(structures)
 
CHAPTER -4-class and structure.pptx
CHAPTER -4-class and structure.pptxCHAPTER -4-class and structure.pptx
CHAPTER -4-class and structure.pptx
 
Computer Programming -II (Lec. 10).pptx
Computer Programming -II (Lec. 10).pptxComputer Programming -II (Lec. 10).pptx
Computer Programming -II (Lec. 10).pptx
 
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
 
data structure and c programing concepts
data structure and c programing conceptsdata structure and c programing concepts
data structure and c programing concepts
 
Lecture 9_Classes.pptx
Lecture 9_Classes.pptxLecture 9_Classes.pptx
Lecture 9_Classes.pptx
 
C++ tutorials
C++ tutorialsC++ tutorials
C++ tutorials
 
C++ Course - Lesson 3
C++ Course - Lesson 3C++ Course - Lesson 3
C++ Course - Lesson 3
 
Arrry structure Stacks in data structure
Arrry structure Stacks  in data structureArrry structure Stacks  in data structure
Arrry structure Stacks in data structure
 
booksoncprogramminglanguage-anintroductiontobeginnersbyarunumrao4-21101016591...
booksoncprogramminglanguage-anintroductiontobeginnersbyarunumrao4-21101016591...booksoncprogramminglanguage-anintroductiontobeginnersbyarunumrao4-21101016591...
booksoncprogramminglanguage-anintroductiontobeginnersbyarunumrao4-21101016591...
 
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...
 
Introduction to c part 2
Introduction to c   part  2Introduction to c   part  2
Introduction to c part 2
 
Oops lecture 1
Oops lecture 1Oops lecture 1
Oops lecture 1
 

Recently uploaded

IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019IES VE
 
Meet the new FSP 3000 M-Flex800™
Meet the new FSP 3000 M-Flex800™Meet the new FSP 3000 M-Flex800™
Meet the new FSP 3000 M-Flex800™Adtran
 
COMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a WebsiteCOMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a Websitedgelyza
 
Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024SkyPlanner
 
VoIP Service and Marketing using Odoo and Asterisk PBX
VoIP Service and Marketing using Odoo and Asterisk PBXVoIP Service and Marketing using Odoo and Asterisk PBX
VoIP Service and Marketing using Odoo and Asterisk PBXTarek Kalaji
 
Empowering Africa's Next Generation: The AI Leadership Blueprint
Empowering Africa's Next Generation: The AI Leadership BlueprintEmpowering Africa's Next Generation: The AI Leadership Blueprint
Empowering Africa's Next Generation: The AI Leadership BlueprintMahmoud Rabie
 
Building Your Own AI Instance (TBLC AI )
Building Your Own AI Instance (TBLC AI )Building Your Own AI Instance (TBLC AI )
Building Your Own AI Instance (TBLC AI )Brian Pichman
 
Videogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdfVideogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdfinfogdgmi
 
UiPath Platform: The Backend Engine Powering Your Automation - Session 1
UiPath Platform: The Backend Engine Powering Your Automation - Session 1UiPath Platform: The Backend Engine Powering Your Automation - Session 1
UiPath Platform: The Backend Engine Powering Your Automation - Session 1DianaGray10
 
OpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability AdventureOpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability AdventureEric D. Schabell
 
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCostKubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCostMatt Ray
 
Artificial Intelligence & SEO Trends for 2024
Artificial Intelligence & SEO Trends for 2024Artificial Intelligence & SEO Trends for 2024
Artificial Intelligence & SEO Trends for 2024D Cloud Solutions
 
Comparing Sidecar-less Service Mesh from Cilium and Istio
Comparing Sidecar-less Service Mesh from Cilium and IstioComparing Sidecar-less Service Mesh from Cilium and Istio
Comparing Sidecar-less Service Mesh from Cilium and IstioChristian Posta
 
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdf
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdfIaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdf
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdfDaniel Santiago Silva Capera
 
Secure your environment with UiPath and CyberArk technologies - Session 1
Secure your environment with UiPath and CyberArk technologies - Session 1Secure your environment with UiPath and CyberArk technologies - Session 1
Secure your environment with UiPath and CyberArk technologies - Session 1DianaGray10
 
Basic Building Blocks of Internet of Things.
Basic Building Blocks of Internet of Things.Basic Building Blocks of Internet of Things.
Basic Building Blocks of Internet of Things.YounusS2
 
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdfUiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdfDianaGray10
 
Building AI-Driven Apps Using Semantic Kernel.pptx
Building AI-Driven Apps Using Semantic Kernel.pptxBuilding AI-Driven Apps Using Semantic Kernel.pptx
Building AI-Driven Apps Using Semantic Kernel.pptxUdaiappa Ramachandran
 
ADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDE
ADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDEADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDE
ADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDELiveplex
 

Recently uploaded (20)

IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
 
Meet the new FSP 3000 M-Flex800™
Meet the new FSP 3000 M-Flex800™Meet the new FSP 3000 M-Flex800™
Meet the new FSP 3000 M-Flex800™
 
COMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a WebsiteCOMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a Website
 
Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024
 
VoIP Service and Marketing using Odoo and Asterisk PBX
VoIP Service and Marketing using Odoo and Asterisk PBXVoIP Service and Marketing using Odoo and Asterisk PBX
VoIP Service and Marketing using Odoo and Asterisk PBX
 
Empowering Africa's Next Generation: The AI Leadership Blueprint
Empowering Africa's Next Generation: The AI Leadership BlueprintEmpowering Africa's Next Generation: The AI Leadership Blueprint
Empowering Africa's Next Generation: The AI Leadership Blueprint
 
Building Your Own AI Instance (TBLC AI )
Building Your Own AI Instance (TBLC AI )Building Your Own AI Instance (TBLC AI )
Building Your Own AI Instance (TBLC AI )
 
Videogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdfVideogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdf
 
UiPath Platform: The Backend Engine Powering Your Automation - Session 1
UiPath Platform: The Backend Engine Powering Your Automation - Session 1UiPath Platform: The Backend Engine Powering Your Automation - Session 1
UiPath Platform: The Backend Engine Powering Your Automation - Session 1
 
OpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability AdventureOpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability Adventure
 
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCostKubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
 
Artificial Intelligence & SEO Trends for 2024
Artificial Intelligence & SEO Trends for 2024Artificial Intelligence & SEO Trends for 2024
Artificial Intelligence & SEO Trends for 2024
 
Comparing Sidecar-less Service Mesh from Cilium and Istio
Comparing Sidecar-less Service Mesh from Cilium and IstioComparing Sidecar-less Service Mesh from Cilium and Istio
Comparing Sidecar-less Service Mesh from Cilium and Istio
 
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdf
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdfIaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdf
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdf
 
Secure your environment with UiPath and CyberArk technologies - Session 1
Secure your environment with UiPath and CyberArk technologies - Session 1Secure your environment with UiPath and CyberArk technologies - Session 1
Secure your environment with UiPath and CyberArk technologies - Session 1
 
Basic Building Blocks of Internet of Things.
Basic Building Blocks of Internet of Things.Basic Building Blocks of Internet of Things.
Basic Building Blocks of Internet of Things.
 
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdfUiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
 
Building AI-Driven Apps Using Semantic Kernel.pptx
Building AI-Driven Apps Using Semantic Kernel.pptxBuilding AI-Driven Apps Using Semantic Kernel.pptx
Building AI-Driven Apps Using Semantic Kernel.pptx
 
ADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDE
ADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDEADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDE
ADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDE
 
201610817 - edge part1
201610817 - edge part1201610817 - edge part1
201610817 - edge part1
 

Lab 13

  • 1. Lab # 13 DE-32 (A) DME
  • 2. ◦ To learn how to declare multidimensional array ◦ To learn how to declare 2D dynamic array using pointers ◦ To learn the use and syntax of the structures
  • 3. Arrays can have two or more dimensions. The two dimensional array is called a matrix. It can be declared as int std[no. of rows][no. of columns];  Two loops are used to input values to the array elements. E.g. for(i=0; i<no. of rows; i++) for(j=0; j<no. of columns; j++) { cin>>std[i][j]; }
  • 4. Like input, two loops are used to display values of the array elements. E.g. for(i=0; i<no. of rows; i++) for(j=0; j<no. of columns; j++) { cout<<std[i][j]; }  Two dimensional arrays can be initialized as; int std[3][2]={{1234,56}, {2356, 99}, {1586, 90}}; int std[][2]={{1234,56}, {2356, 99}, {1586, 90}};
  • 5. Pointers in C++ can also be used to declare a 2D dynamic array in which you can specify the number of rows and columns at the runtime.  First you have to declare a double pointer mean a pointer that point to a variable pointer then we allocate memory for the variable pointers of any size we want and at last we will go to each location of the pointers and allocate memory for variables of any size. This can be done as int **m; m = new int* [size]; //array of pointers for ( int i=0; i<size; i++) m[i] = new int [size];
  • 7. #include<iostream> using namespace std; void main() { int size; cin>>size; int **num; num= new int*[size]; for(int i=0;i<size;i++) num[i]=new int[size]; for(int i=0;i<size;i++) for(int j=0;j<size;j++) cin>>num[i][j]; for(int i=0;i<size;i++) { for(int j=0;j<size;j++) { cout<<num[i][j]<<'t'; } cout<<endl; } }
  • 8. A structure is a collection of simple variables that can be of different types and functions. The data items in a structure are called members of a structure. Structures are defined using ‘struct’ keyword followed by the user defined name for the structure e.g. struct name { int a; //data member float b; //data member string c; //data member void function(); //member function }; //definition of structure ends with a semi-colon  After the definition of the structure you can declare objects of the structure just like you declare a variable. To access the data and function member of a structure dot operator is used e.g. void main() { name n1; n1.a = 10; n1.b = 2.3; n1.c = “Hello “; //storing value in a data member n1.function(); //calling member function }
  • 9. struct name { int a; //data member float b; //data member string c; //data member void function() { cout<<"HELLO WORLD"; }//member function }n; struct name { int a; //data member float b; //data member string c; //data member void function() { cout<<"HELLO WORLD"; }//member function }; struct name n;
  • 10. struct name { int a; //data member float b; //data member string c; //data member void function() { cout<<"HELLO WORLD"; }//member function }; struct name n={10,20.0,"Hello"};
  • 11. struct book { string name; float price; int pages; }; struct book b[100]; void main() { int i; for(i=0;i<100;i++) { cin>>b[i].name>>b[i].price>>b[i].pages; } for(i=0;i<100;i++) { cout<<b[i].name<<b[i].price<<b[i].pages<<endl; } }