SlideShare a Scribd company logo
Dynamic Allocation in C++
allan914.120418 (update: 120420)
Example 1
#include<iostream>
using namespace std;

int main()
{
     int* a;
     int n;
     cin >> n;
     a=new int [n];
     for(int i=0;i<n;i++) a[i]=i+1;
     for(int i=0;i<n;i++) cout << a[i] << " ";
     delete [] a;
     return 0;
}
Example 1: Result
Sample Input
10

 Sample Output
1 2 3 4 5 6 7 8 9 10
Example 2
#include<iostream>
using namespace std;

int main() {
     int** a; int n,m;
     cin >> n; cin >> m;
     a=new int* [n];
     for(int i=0;i<n;i++) a[i]=new int [m];
     for(int i=0;i<n;i++) for(int j=0;j<m;j++) a[i][j]=i+j+1;
     for(int i=0;i<n;i++) {
            for(int j=0;j<m;j++) cout << a[i][j] << " ";
            cout << endl;
     }
     for(int i=0;i<n;i++) delete [] a[i];
     delete [] a;
     return 0;
}
Example 2: Result
   Sample Input
5
4
Sample Output
1234
2345
3456
4567
5678
Example 3
#include<iostream>
using namespace std;

int main() {
        int* a;
        int n,m;
        cin >> n;
        cin >> m;
        a=new int [n*m];
        int** b;
        b=new int* [n];
        for(int i=0;i<n;i++) b[i]=&(a[n*i]);
        for(int i=0;i<n;i++) for(int j=0;j<m;j++) b[i][j]=i+j+1;
        for(int i=0;i<n;i++) {
                 for(int j=0;j<m;j++) cout << b[i][j] << " ";
//cautious with CodeBlocks !
                 cout << endl;
        }
        delete [] b;
        delete [] a;
        return 0;
}
Example 3: Result
   Sample Input
5
4
Sample Output
1234
2345
3456
4567
5678
Example 4
// Headers emitted, cautious with CodeBlocks !
void* new2d(int n,int m,int size) {
        void **a = new void* [m*sizeof(void*) + n*m*size];
        for(int j=0;j<m;j++) a[j] = ((char *)(a+m)) + j*n*size;
        return a;
}

int main() {
        int** a;
        int n,m;
        cin >> n;
        cin >> m;
        a = (int**)new2d(n,n,sizeof(int));
        for(int i=0;i<n;i++) for(int j=0;j<m;j++) a[i][j]=i+j+1;
        for(int i=0;i<n;i++) {
                 for(int j=0;j<m;j++) cout << a[i][j] << " ";
                 cout << endl;
        }
        delete [] a;
        return 0;
}
Example 4: Result
   Sample Input
5
4
Sample Output
1234
2345
3456
4567
5678
Example 5
#include<iostream>
#include<vector>
using namespace std;

int main() {
     int n,m;
     cin >> n;
     cin >> m;
     vector<vector<int> > a(n, vector<int>(m));
     for(int i=0;i<n;i++) for(int j=0;j<m;j++) a[i][j]=i+j+1;
     for(int i=0;i<n;i++) {
            for(int j=0;j<m;j++) cout << a[i][j] << " ";
            cout << endl;
     }
     return 0;
}
Example 5: Result
   Sample Input
5
4
Sample Output
1234
2345
3456
4567
5678

More Related Content

What's hot

C++ TUTORIAL 3
C++ TUTORIAL 3C++ TUTORIAL 3
C++ TUTORIAL 3
Farhan Ab Rahman
 
CUDA First Programs: Computer Architecture CSE448 : UAA Alaska : Notes
CUDA First Programs: Computer Architecture CSE448 : UAA Alaska : NotesCUDA First Programs: Computer Architecture CSE448 : UAA Alaska : Notes
CUDA First Programs: Computer Architecture CSE448 : UAA Alaska : Notes
Subhajit Sahu
 
Programa.eje
Programa.ejePrograma.eje
Programa.eje
guapi387
 
C++ ARRAY WITH EXAMPLES
C++ ARRAY WITH EXAMPLESC++ ARRAY WITH EXAMPLES
C++ ARRAY WITH EXAMPLES
Farhan Ab Rahman
 
C++ TUTORIAL 9
C++ TUTORIAL 9C++ TUTORIAL 9
C++ TUTORIAL 9
Farhan Ab Rahman
 
Static Variable in C++
Static Variable in C++Static Variable in C++
Static Variable in C++
Nasir Hamidon
 
Class array
Class arrayClass array
Class array
nky92
 
Oop lab report
Oop lab reportOop lab report
Oop lab report
khasmanjalali
 
1
11
C# Assignmet Help
C# Assignmet HelpC# Assignmet Help
C# Assignmet Help
Programming Homework Help
 
Permute
PermutePermute
C questions
C questionsC questions
C questions
mohamed sikander
 
Permute
PermutePermute
Tugas struktur data terakhir_pohonBiner
Tugas struktur data terakhir_pohonBinerTugas struktur data terakhir_pohonBiner
Tugas struktur data terakhir_pohonBiner
Boscasimbolon Boscasimbolon
 
Doubly linklist
Doubly linklistDoubly linklist
Doubly linklist
ilsamaryum
 
Extending built in objects
Extending built in objectsExtending built in objects
Extending built in objects
Muhammad Ahmed
 
Lo17
Lo17Lo17
Lo17
liankei
 
Boundary Fill Algorithm in C
Boundary Fill Algorithm in CBoundary Fill Algorithm in C
Boundary Fill Algorithm in C
Kasun Ranga Wijeweera
 
Function basics
Function basicsFunction basics
Function basics
mohamed sikander
 
Rumus VB-2
Rumus VB-2Rumus VB-2
Rumus VB-2
T. Astari
 

What's hot (20)

C++ TUTORIAL 3
C++ TUTORIAL 3C++ TUTORIAL 3
C++ TUTORIAL 3
 
CUDA First Programs: Computer Architecture CSE448 : UAA Alaska : Notes
CUDA First Programs: Computer Architecture CSE448 : UAA Alaska : NotesCUDA First Programs: Computer Architecture CSE448 : UAA Alaska : Notes
CUDA First Programs: Computer Architecture CSE448 : UAA Alaska : Notes
 
Programa.eje
Programa.ejePrograma.eje
Programa.eje
 
C++ ARRAY WITH EXAMPLES
C++ ARRAY WITH EXAMPLESC++ ARRAY WITH EXAMPLES
C++ ARRAY WITH EXAMPLES
 
C++ TUTORIAL 9
C++ TUTORIAL 9C++ TUTORIAL 9
C++ TUTORIAL 9
 
Static Variable in C++
Static Variable in C++Static Variable in C++
Static Variable in C++
 
Class array
Class arrayClass array
Class array
 
Oop lab report
Oop lab reportOop lab report
Oop lab report
 
1
11
1
 
C# Assignmet Help
C# Assignmet HelpC# Assignmet Help
C# Assignmet Help
 
Permute
PermutePermute
Permute
 
C questions
C questionsC questions
C questions
 
Permute
PermutePermute
Permute
 
Tugas struktur data terakhir_pohonBiner
Tugas struktur data terakhir_pohonBinerTugas struktur data terakhir_pohonBiner
Tugas struktur data terakhir_pohonBiner
 
Doubly linklist
Doubly linklistDoubly linklist
Doubly linklist
 
Extending built in objects
Extending built in objectsExtending built in objects
Extending built in objects
 
Lo17
Lo17Lo17
Lo17
 
Boundary Fill Algorithm in C
Boundary Fill Algorithm in CBoundary Fill Algorithm in C
Boundary Fill Algorithm in C
 
Function basics
Function basicsFunction basics
Function basics
 
Rumus VB-2
Rumus VB-2Rumus VB-2
Rumus VB-2
 

Viewers also liked

Replastificacion
ReplastificacionReplastificacion
Replastificacion
German Velazquez Cardenas
 
Креатив в действии: конверсия в результат
Креатив в действии: конверсия в результатКреатив в действии: конверсия в результат
Креатив в действии: конверсия в результат
EMAILMATRIX
 
Автоматизация емейл-маркетинга: от простого к сложному
Автоматизация емейл-маркетинга: от простого к сложномуАвтоматизация емейл-маркетинга: от простого к сложному
Автоматизация емейл-маркетинга: от простого к сложному
EMAILMATRIX
 
Как запустить емейл маркетинг в кратчайшие сроки
Как запустить емейл маркетинг в кратчайшие срокиКак запустить емейл маркетинг в кратчайшие сроки
Как запустить емейл маркетинг в кратчайшие сроки
EMAILMATRIX
 
мероприятия
мероприятиямероприятия
мероприятияElenaSam
 
Емейл-маркетинг: как поднять целину
Емейл-маркетинг: как поднять целинуЕмейл-маркетинг: как поднять целину
Емейл-маркетинг: как поднять целину
EMAILMATRIX
 
выпуск 7
выпуск 7выпуск 7
выпуск 7ElenaSam
 
здоровый образ жизни
здоровый  образ жизниздоровый  образ жизни
здоровый образ жизниElenaSam
 
Latihan reproduction
Latihan reproductionLatihan reproduction
Latihan reproductionruziana1986
 
урок мужества
урок мужестваурок мужества
урок мужестваElenaSam
 
Черепанова и Малыхина
Черепанова и МалыхинаЧерепанова и Малыхина
Черепанова и МалыхинаElenaSam
 
итоги педсовет
итоги педсоветитоги педсовет
итоги педсоветElenaSam
 
EoinWoods_WhereDidMyArchitectureGoPreservingSoftwareArchitectureInItsImplemen...
EoinWoods_WhereDidMyArchitectureGoPreservingSoftwareArchitectureInItsImplemen...EoinWoods_WhereDidMyArchitectureGoPreservingSoftwareArchitectureInItsImplemen...
EoinWoods_WhereDidMyArchitectureGoPreservingSoftwareArchitectureInItsImplemen...
Kostas Mavridis
 
Hayashi masw gravity
Hayashi masw gravityHayashi masw gravity
Hayashi masw gravity
hugang2003
 
зарница
зарницазарница
зарницаElenaSam
 
Friends
Friends Friends
Friends
Aasif Farooki
 
итоги чемпионат2013
итоги чемпионат2013итоги чемпионат2013
итоги чемпионат2013ElenaSam
 

Viewers also liked (20)

Replastificacion
ReplastificacionReplastificacion
Replastificacion
 
Креатив в действии: конверсия в результат
Креатив в действии: конверсия в результатКреатив в действии: конверсия в результат
Креатив в действии: конверсия в результат
 
Автоматизация емейл-маркетинга: от простого к сложному
Автоматизация емейл-маркетинга: от простого к сложномуАвтоматизация емейл-маркетинга: от простого к сложному
Автоматизация емейл-маркетинга: от простого к сложному
 
квн
квнквн
квн
 
соко
сокосоко
соко
 
Как запустить емейл маркетинг в кратчайшие сроки
Как запустить емейл маркетинг в кратчайшие срокиКак запустить емейл маркетинг в кратчайшие сроки
Как запустить емейл маркетинг в кратчайшие сроки
 
мероприятия
мероприятиямероприятия
мероприятия
 
Емейл-маркетинг: как поднять целину
Емейл-маркетинг: как поднять целинуЕмейл-маркетинг: как поднять целину
Емейл-маркетинг: как поднять целину
 
выпуск 7
выпуск 7выпуск 7
выпуск 7
 
здоровый образ жизни
здоровый  образ жизниздоровый  образ жизни
здоровый образ жизни
 
Latihan reproduction
Latihan reproductionLatihan reproduction
Latihan reproduction
 
урок мужества
урок мужестваурок мужества
урок мужества
 
Черепанова и Малыхина
Черепанова и МалыхинаЧерепанова и Малыхина
Черепанова и Малыхина
 
итоги педсовет
итоги педсоветитоги педсовет
итоги педсовет
 
EoinWoods_WhereDidMyArchitectureGoPreservingSoftwareArchitectureInItsImplemen...
EoinWoods_WhereDidMyArchitectureGoPreservingSoftwareArchitectureInItsImplemen...EoinWoods_WhereDidMyArchitectureGoPreservingSoftwareArchitectureInItsImplemen...
EoinWoods_WhereDidMyArchitectureGoPreservingSoftwareArchitectureInItsImplemen...
 
Hayashi masw gravity
Hayashi masw gravityHayashi masw gravity
Hayashi masw gravity
 
зарница
зарницазарница
зарница
 
Friends
Friends Friends
Friends
 
итоги чемпионат2013
итоги чемпионат2013итоги чемпионат2013
итоги чемпионат2013
 
Presentation3
Presentation3Presentation3
Presentation3
 

Similar to OOP 2012 - Hint: Dynamic allocation in c++

C++ Programming - 2nd Study
C++ Programming - 2nd StudyC++ Programming - 2nd Study
C++ Programming - 2nd Study
Chris Ohk
 
ماترێکس به‌ کوردی ئارام
ماترێکس به‌ کوردی ئارامماترێکس به‌ کوردی ئارام
ماترێکس به‌ کوردی ئارام
Aram Jamal
 
CPP Language Basics - Reference
CPP Language Basics - ReferenceCPP Language Basics - Reference
CPP Language Basics - Reference
Mohammed Sikander
 
Go vs C++ - CppRussia 2019 Piter BoF
Go vs C++ - CppRussia 2019 Piter BoFGo vs C++ - CppRussia 2019 Piter BoF
Go vs C++ - CppRussia 2019 Piter BoF
Timur Safin
 
C++ practical
C++ practicalC++ practical
C++ practical
Rahul juneja
 
Ejercicios de programacion
Ejercicios de programacionEjercicios de programacion
Ejercicios de programacion
Jeff Tu Pechito
 
oodp elab.pdf
oodp elab.pdfoodp elab.pdf
oodp elab.pdf
SWATIKUMARIRA2111030
 
C++ file
C++ fileC++ file
C++ file
Mukund Trivedi
 
C++ file
C++ fileC++ file
C++ file
Mukund Trivedi
 
C++ lectures all chapters in one slide.pptx
C++ lectures all chapters in one slide.pptxC++ lectures all chapters in one slide.pptx
C++ lectures all chapters in one slide.pptx
ssuser3cbb4c
 
Oops lab manual2
Oops lab manual2Oops lab manual2
Oops lab manual2
Mouna Guru
 
Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...
Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...
Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...
ssuserd6b1fd
 
Introduction to cpp (c++)
Introduction to cpp (c++)Introduction to cpp (c++)
Introduction to cpp (c++)
Arun Umrao
 
Cpp c++ 1
Cpp c++ 1Cpp c++ 1
Computer_Practicals-file.doc.pdf
Computer_Practicals-file.doc.pdfComputer_Practicals-file.doc.pdf
Computer_Practicals-file.doc.pdf
HIMANSUKUMAR12
 
Arrays
ArraysArrays
array2d.ppt
array2d.pptarray2d.ppt
array2d.ppt
DeveshDewangan5
 
C++ L05-Functions
C++ L05-FunctionsC++ L05-Functions
C++ L05-Functions
Mohammad Shaker
 
54602399 c-examples-51-to-108-programe-ee01083101
54602399 c-examples-51-to-108-programe-ee0108310154602399 c-examples-51-to-108-programe-ee01083101
54602399 c-examples-51-to-108-programe-ee01083101
premrings
 
Lab Manual IV (1).pdf on C++ Programming practice
Lab Manual IV (1).pdf on C++ Programming practiceLab Manual IV (1).pdf on C++ Programming practice
Lab Manual IV (1).pdf on C++ Programming practice
ranaibrahim453
 

Similar to OOP 2012 - Hint: Dynamic allocation in c++ (20)

C++ Programming - 2nd Study
C++ Programming - 2nd StudyC++ Programming - 2nd Study
C++ Programming - 2nd Study
 
ماترێکس به‌ کوردی ئارام
ماترێکس به‌ کوردی ئارامماترێکس به‌ کوردی ئارام
ماترێکس به‌ کوردی ئارام
 
CPP Language Basics - Reference
CPP Language Basics - ReferenceCPP Language Basics - Reference
CPP Language Basics - Reference
 
Go vs C++ - CppRussia 2019 Piter BoF
Go vs C++ - CppRussia 2019 Piter BoFGo vs C++ - CppRussia 2019 Piter BoF
Go vs C++ - CppRussia 2019 Piter BoF
 
C++ practical
C++ practicalC++ practical
C++ practical
 
Ejercicios de programacion
Ejercicios de programacionEjercicios de programacion
Ejercicios de programacion
 
oodp elab.pdf
oodp elab.pdfoodp elab.pdf
oodp elab.pdf
 
C++ file
C++ fileC++ file
C++ file
 
C++ file
C++ fileC++ file
C++ file
 
C++ lectures all chapters in one slide.pptx
C++ lectures all chapters in one slide.pptxC++ lectures all chapters in one slide.pptx
C++ lectures all chapters in one slide.pptx
 
Oops lab manual2
Oops lab manual2Oops lab manual2
Oops lab manual2
 
Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...
Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...
Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...
 
Introduction to cpp (c++)
Introduction to cpp (c++)Introduction to cpp (c++)
Introduction to cpp (c++)
 
Cpp c++ 1
Cpp c++ 1Cpp c++ 1
Cpp c++ 1
 
Computer_Practicals-file.doc.pdf
Computer_Practicals-file.doc.pdfComputer_Practicals-file.doc.pdf
Computer_Practicals-file.doc.pdf
 
Arrays
ArraysArrays
Arrays
 
array2d.ppt
array2d.pptarray2d.ppt
array2d.ppt
 
C++ L05-Functions
C++ L05-FunctionsC++ L05-Functions
C++ L05-Functions
 
54602399 c-examples-51-to-108-programe-ee01083101
54602399 c-examples-51-to-108-programe-ee0108310154602399 c-examples-51-to-108-programe-ee01083101
54602399 c-examples-51-to-108-programe-ee01083101
 
Lab Manual IV (1).pdf on C++ Programming practice
Lab Manual IV (1).pdf on C++ Programming practiceLab Manual IV (1).pdf on C++ Programming practice
Lab Manual IV (1).pdf on C++ Programming practice
 

Recently uploaded

20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
Matthew Sinclair
 
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AIEnchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Vladimir Iglovikov, Ph.D.
 
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
Edge AI and Vision Alliance
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
SOFTTECHHUB
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
Matthew Sinclair
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Malak Abu Hammad
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
innovationoecd
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
Alpen-Adria-Universität
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
Matthew Sinclair
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
名前 です男
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Paige Cruz
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems S.M.S.A.
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
Neo4j
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
Aftab Hussain
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
DianaGray10
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
Octavian Nadolu
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
shyamraj55
 

Recently uploaded (20)

20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
 
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AIEnchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
 
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
 

OOP 2012 - Hint: Dynamic allocation in c++

  • 1. Dynamic Allocation in C++ allan914.120418 (update: 120420)
  • 2. Example 1 #include<iostream> using namespace std; int main() { int* a; int n; cin >> n; a=new int [n]; for(int i=0;i<n;i++) a[i]=i+1; for(int i=0;i<n;i++) cout << a[i] << " "; delete [] a; return 0; }
  • 3. Example 1: Result Sample Input 10  Sample Output 1 2 3 4 5 6 7 8 9 10
  • 4. Example 2 #include<iostream> using namespace std; int main() { int** a; int n,m; cin >> n; cin >> m; a=new int* [n]; for(int i=0;i<n;i++) a[i]=new int [m]; for(int i=0;i<n;i++) for(int j=0;j<m;j++) a[i][j]=i+j+1; for(int i=0;i<n;i++) { for(int j=0;j<m;j++) cout << a[i][j] << " "; cout << endl; } for(int i=0;i<n;i++) delete [] a[i]; delete [] a; return 0; }
  • 5. Example 2: Result  Sample Input 5 4 Sample Output 1234 2345 3456 4567 5678
  • 6. Example 3 #include<iostream> using namespace std; int main() { int* a; int n,m; cin >> n; cin >> m; a=new int [n*m]; int** b; b=new int* [n]; for(int i=0;i<n;i++) b[i]=&(a[n*i]); for(int i=0;i<n;i++) for(int j=0;j<m;j++) b[i][j]=i+j+1; for(int i=0;i<n;i++) { for(int j=0;j<m;j++) cout << b[i][j] << " "; //cautious with CodeBlocks ! cout << endl; } delete [] b; delete [] a; return 0; }
  • 7. Example 3: Result  Sample Input 5 4 Sample Output 1234 2345 3456 4567 5678
  • 8. Example 4 // Headers emitted, cautious with CodeBlocks ! void* new2d(int n,int m,int size) { void **a = new void* [m*sizeof(void*) + n*m*size]; for(int j=0;j<m;j++) a[j] = ((char *)(a+m)) + j*n*size; return a; } int main() { int** a; int n,m; cin >> n; cin >> m; a = (int**)new2d(n,n,sizeof(int)); for(int i=0;i<n;i++) for(int j=0;j<m;j++) a[i][j]=i+j+1; for(int i=0;i<n;i++) { for(int j=0;j<m;j++) cout << a[i][j] << " "; cout << endl; } delete [] a; return 0; }
  • 9. Example 4: Result  Sample Input 5 4 Sample Output 1234 2345 3456 4567 5678
  • 10. Example 5 #include<iostream> #include<vector> using namespace std; int main() { int n,m; cin >> n; cin >> m; vector<vector<int> > a(n, vector<int>(m)); for(int i=0;i<n;i++) for(int j=0;j<m;j++) a[i][j]=i+j+1; for(int i=0;i<n;i++) { for(int j=0;j<m;j++) cout << a[i][j] << " "; cout << endl; } return 0; }
  • 11. Example 5: Result  Sample Input 5 4 Sample Output 1234 2345 3456 4567 5678