SlideShare a Scribd company logo
1 of 11
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];
#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 - Arrays, Pointers, Structures

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 - Arrays, Pointers, Structures (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

Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 

Recently uploaded (20)

Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 

Lab 13 - Arrays, Pointers, Structures

  • 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];
  • 6.
  • 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; } }