Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
OOP 2012 - Hint: Dynamic allocation in c++
Search
allan914
May 08, 2012
Programming
78
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
OOP 2012 - Hint: Dynamic allocation in c++
allan914
May 08, 2012
More Decks by allan914
See All by allan914
ICS 2012 - Midterm Solution for Problem 1-3
allan914
0
78
Other Decks in Programming
See All in Programming
Long Living Tokens, Die, Die, Die! (or: The One Ring is Banned in Modern)
sylph01
0
300
機械に任せるテスト、人が見るテスト ⽣成AIで引き直した、運⽤保守フェーズの線引き
dske104
0
190
AI時代のコードレビューは人に向けるな、仕組みに向けろ
texmeijin
5
3.7k
ソニーのクラウド共通基盤の変遷とAI時代の開発スタイルに合わせた進化 / The Journey of Sony’s Common Cloud Platform and Its Evolution for AI-Native Development
kenjiyoneyama
0
270
3回つくってわかった、 定期実行ジョブ基盤の本質情報
takai
0
470
Atomic Design, Enforced: Scaling Mobile Design Systems (next.app devCon / droidCon Berlin 2026)
steliosf
PRO
0
170
Jetpack Compose Mechanisms
skydoves
3
820
ChromeでローカルLLM
ryu1013
0
140
AIに “答え“を書かせるのを やめてみた
___akari11
0
120
phperだってパンチカードでコーディングしたい
o0h
PRO
0
340
Everything will be SERVERLESS — 信じて運用した10年の経験値 / Everything Will be Serverless — Lessons Learned from 10 Years of Operational Experience
seike460
PRO
1
1.1k
動作中のプログラムの中身をリアルタイムに覗く / Realtime Debugger for CSharp with Roslyn
prota
1
1.9k
Featured
See All Featured
The agentic SEO stack - context over prompts
schlessera
0
970
SEO in 2025: How to Prepare for the Future of Search
ipullrank
3
3.9k
Navigating Team Friction
lara
192
16k
Claude Code どこまでも/ Claude Code Everywhere
nwiizo
68
59k
WENDY [Excerpt]
tessaabrams
14
40k
エンジニアに許された特別な時間の終わり
watany
109
250k
My Coaching Mixtape
mlcsv
0
360
4 Signs Your Business is Dying
shpigford
187
23k
Impact Scores and Hybrid Strategies: The future of link building
tamaranovitovic
0
460
How to audit for AI Accessibility on your Front & Back End
davetheseo
0
600
SERP Conf. Vienna - Web Accessibility: Optimizing for Inclusivity and SEO
sarafernandez
2
1.6k
From π to Pie charts
rasagy
1
400
Transcript
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 1 2 3 4 2 3 4 5 3 4 5 6 4 5 6 7 5 6 7 8
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 1 2 3 4 2 3 4 5 3 4 5 6 4 5 6 7 5 6 7 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(m,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 1 2 3 4 2 3 4 5 3 4 5 6 4 5 6 7 5 6 7 8
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 1 2 3 4 2 3 4 5 3 4 5 6 4 5 6 7 5 6 7 8