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
43
CSC364 Lecture 17
javiergs
PRO
0
160
CSC307_L17_review_5050.pdf
javiergs
PRO
0
22
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
71
CSC364 Lecture 14
javiergs
PRO
0
150
CSC307 Lecture 14
javiergs
PRO
0
480
Other Decks in Programming
See All in Programming
脱 雰囲気実装!AgentCoreを良い感じにWEBアプリケーションに組み込むために
takuyay0ne
3
420
AI Assistants for YourAngular Solutions @Angular Graz, March 2026
manfredsteyer
PRO
0
130
AI時代の脳疲弊と向き合う ~言語学としてのPHP~
sakuraikotone
1
1.8k
飯MCP
yusukebe
0
440
存在論的プログラミング: 時間と存在を記述する
koriym
5
740
GoのDB アクセスにおける 「型安全」と「柔軟性」の両立 - Bob という選択肢
tak848
0
290
20260315 AWSなんもわからん🥲
chiilog
2
180
「速くなった気がする」をデータで疑う
senleaf24
0
120
Symfonyの特性(設計思想)を手軽に活かす特性(trait)
ickx
0
110
Ruby and LLM Ecosystem 2nd
koic
1
1.4k
年間50登壇、単著出版、雑誌寄稿、Podcast出演、YouTube、CM、カンファレンス主催……全部やってみたので面白さ等を比較してみよう / I’ve tried them all, so let’s compare how interesting they are.
nrslib
4
610
今年もTECHSCOREブログを書き続けます!
hiraoku101
0
210
Featured
See All Featured
Learning to Love Humans: Emotional Interface Design
aarron
275
41k
Data-driven link building: lessons from a $708K investment (BrightonSEO talk)
szymonslowik
1
990
Information Architects: The Missing Link in Design Systems
soysaucechin
0
850
[SF Ruby Conf 2025] Rails X
palkan
2
880
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
35
2.4k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
130k
Pawsitive SEO: Lessons from My Dog (and Many Mistakes) on Thriving as a Consultant in the Age of AI
davidcarrasco
0
97
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
10
1.1k
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
11
870
Into the Great Unknown - MozCon
thekraken
40
2.3k
Leveraging Curiosity to Care for An Aging Population
cassininazir
1
200
4 Signs Your Business is Dying
shpigford
187
22k
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.