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
0
2.4k
CSE240 Lecture 11
Introduction to Programming Languages
malloc and free
(202202)
Javier Gonzalez-Sanchez
PRO
January 11, 2017
Tweet
Share
More Decks by Javier Gonzalez-Sanchez
See All by Javier Gonzalez-Sanchez
CSC307 Lecture 02
javiergs
PRO
1
710
CSC307 Lecture 01
javiergs
PRO
0
640
CSC364 Lecture 01
javiergs
PRO
0
87
CSC509 Lecture 15
javiergs
PRO
0
49
CSC305 Lecture 18
javiergs
PRO
0
280
CSC509 Lecture 14
javiergs
PRO
0
230
CSC305 Lecture 17
javiergs
PRO
0
350
CSC305 Lecture 16
javiergs
PRO
0
390
CSC305 Lecture 15
javiergs
PRO
0
260
Other Decks in Programming
See All in Programming
GoLab2025 Recap
kuro_kurorrr
0
790
tparseでgo testの出力を見やすくする
utgwkk
2
330
マスタデータ問題、マイクロサービスでどう解くか
kts
0
160
Giselleで作るAI QAアシスタント 〜 Pull Requestレビューに継続的QAを
codenote
0
320
新卒エンジニアのプルリクエスト with AI駆動
fukunaga2025
0
240
Spinner 軸ズレ現象を調べたらレンダリング深淵に飲まれた #レバテックMeetup
bengo4com
1
210
Combinatorial Interview Problems with Backtracking Solutions - From Imperative Procedural Programming to Declarative Functional Programming - Part 2
philipschwarz
PRO
0
130
これならできる!個人開発のすゝめ
tinykitten
PRO
0
140
実はマルチモーダルだった。ブラウザの組み込みAI🧠でWebの未来を感じてみよう #jsfes #gemini
n0bisuke2
3
1.4k
生成AIを利用するだけでなく、投資できる組織へ
pospome
2
430
まだ間に合う!Claude Code元年をふりかえる
nogu66
5
920
[AtCoder Conference 2025] LLMを使った業務AHCの上⼿な解き⽅
terryu16
6
970
Featured
See All Featured
Deep Space Network (abreviated)
tonyrice
0
32
SEOcharity - Dark patterns in SEO and UX: How to avoid them and build a more ethical web
sarafernandez
0
96
Utilizing Notion as your number one productivity tool
mfonobong
2
190
Music & Morning Musume
bryan
46
7k
How to train your dragon (web standard)
notwaldorf
97
6.5k
sira's awesome portfolio website redesign presentation
elsirapls
0
99
Prompt Engineering for Job Search
mfonobong
0
130
RailsConf 2023
tenderlove
30
1.3k
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
122
21k
Jess Joyce - The Pitfalls of Following Frameworks
techseoconnect
PRO
1
37
Practical Orchestrator
shlominoach
190
11k
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.