Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
CSE240 Lecture 11
Search
Javier Gonzalez-Sanchez
PRO
January 11, 2017
Programming
2.4k
0
Share
CSE240 Lecture 11
Introduction to Programming Languages
malloc and free
(202202)
Javier Gonzalez-Sanchez
PRO
January 11, 2017
More Decks by Javier Gonzalez-Sanchez
See All by Javier Gonzalez-Sanchez
CSC364 Lecture 18
javiergs
PRO
0
49
CSC364 Lecture 17
javiergs
PRO
0
170
CSC307_L17_review_5050.pdf
javiergs
PRO
0
26
CSC307 Lecture 16
javiergs
PRO
0
270
CSC364 Lecture 16
javiergs
PRO
0
180
CSC307 Lecture 15
javiergs
PRO
0
280
CSC364 Lecture 15
javiergs
PRO
0
79
CSC364 Lecture 14
javiergs
PRO
0
150
CSC307 Lecture 14
javiergs
PRO
0
490
Other Decks in Programming
See All in Programming
10年分の技術的負債、完済へ ― Claude Code主導のAI駆動開発でスポーツブルを丸ごとリプレイスした話
takuya_houshima
0
2.6k
ローカルで稼働するAI エージェントを超えて / beyond-local-ai-agents
gawa
3
280
おれのAgentic Coding 2026/03
tsukasagr
1
150
Back to the roots of date
jinroq
0
100
[RubyKaigi 2026] Require Hooks
palkan
1
200
「Linuxサーバー構築標準教科書」を読んでみた #ツナギメオフライン.7
akase244
0
1.4k
CursorとClaudeCodeとCodexとOpenCodeを実際に比較してみた
terisuke
1
470
実用!Hono RPC2026
yodaka
2
230
煩雑なSkills管理をSoC(関心の分離)により解決する――関心を分離し、プロンプトを部品として育てるためのOSSを作った話 / Solving Complex Skills Management Through SoC (Separation of Concerns)
nrslib
4
950
AI-DLC Deep Dive
yuukiyo
9
4.2k
ハーネスエンジニアリングとは?
kinopeee
10
5.3k
Xdebug と IDE による デバッグ実行の仕組みを見る / Exploring-How-Debugging-Works-with-Xdebug-and-an-IDE
shin1x1
0
380
Featured
See All Featured
Measuring Dark Social's Impact On Conversion and Attribution
stephenakadiri
1
190
Why Our Code Smells
bkeepers
PRO
340
58k
The agentic SEO stack - context over prompts
schlessera
0
750
Mind Mapping
helmedeiros
PRO
1
150
How to Talk to Developers About Accessibility
jct
2
180
Building an army of robots
kneath
306
46k
Discover your Explorer Soul
emna__ayadi
2
1.1k
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
Ethics towards AI in product and experience design
skipperchong
2
260
Believing is Seeing
oripsolob
1
110
Test your architecture with Archunit
thirion
1
2.2k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
17k
Transcript
jgs CSE 240 Introduction to Programming Languages Lecture 11: malloc
and free Dr. Javier Gonzalez-Sanchez
[email protected]
javiergs.engineering.asu.edu | javiergs.com PERALTA 230U Office Hours: By appointment
Javier Gonzalez-Sanchez | CSE240 | Spring 2018 | 2 jgs
Announcement § Homework 02 Programming with C
jgs malloc and free
Javier Gonzalez-Sanchez | CSE240 | Spring 2018 | 4 jgs
malloc #include <stdio.h> #include <stdlib.h> int main(){ int x = 5; int *y = (int*) malloc (sizeof(int)); *y = 7; printf("value of y: %d \n", *y); printf("address of y: %p \n", y); printf("address of y: %p \n", &y); printf("value of x: %d \n", x); printf("address of x: %p \n", &x); free(y); return 0; } 7 0x1c 0x1c y 0x78 5 x 0x74
Javier Gonzalez-Sanchez | CSE240 | Spring 2018 | 5 jgs
malloc and arrays #include <stdio.h> #include <stdlib.h> int main(){ int x = 5; int *y = (int*) malloc (sizeof(int) * 3); *(y+0) = 1; y[1] = 5; *(y+2) = 7; printf("value of y[0]: %d \n", y[0]); printf("value of y[1]: %d \n", y[1]); printf("value of y[2]: %d \n", y[2]); free(y); return 0; } 1 0x1c 0x1c y 0x78 5 7
Javier Gonzalez-Sanchez | CSE240 | Spring 2018 | 6 jgs
malloc and 2D arrays #include <stdio.h> #include <stdlib.h> int main(){ int **array = (int**) malloc (sizeof(int*) * 3); *(array+0) = (int*) malloc (sizeof(int ) * 3); array[1] = (int*) malloc (sizeof(int ) * 3); *(array+2) = (int*) malloc (sizeof(int ) * 3); array[0][0] = 1; array[1][1] = 1; array[2][2] = 1; *(*(array +1 ) + 2) = 3; // this is array[1][2] printf ("array [1][2] is %d \n", array[1][2]); printf ("array [2][2] is %d \n", *(*(array+2)+2) ); // free (s) go here return 0; }
jgs Test Yourselves
Javier Gonzalez-Sanchez | CSE240 | Spring 2018 | 8 jgs
Dynamic 2D Array
Javier Gonzalez-Sanchez | CSE240 | Spring 2018 | 9 jgs
Dynamic 2D Array
Javier Gonzalez-Sanchez | CSE240 | Spring 2018 | 10 jgs
Questions
jgs CSE 240 Introduction to Programming Languages Javier Gonzalez-Sanchez, Ph.D.
[email protected]
Fall 2021 Copyright. These slides can only be used as study material for the class CSE240 at Arizona State University. They cannot be distributed or used for another purpose.