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.3k
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 16
javiergs
PRO
0
150
CSC570 Lecture 13
javiergs
PRO
0
37
CSC307 Lecture 17
javiergs
PRO
0
120
UP Lecture 30
javiergs
PRO
0
83
UP Lecture 25
javiergs
PRO
0
74
CSC486 Lecture 14
javiergs
PRO
0
150
CSC486 Lecture 13
javiergs
PRO
0
110
CSC486 Lecture 12
javiergs
PRO
0
110
CSC486 Lecture 11
javiergs
PRO
0
66
Other Decks in Programming
See All in Programming
What Spring Developers Should Know About Jakarta EE
ivargrimstad
0
420
Composerが「依存解決」のためにどんな工夫をしているか #phpcon
o0h
PRO
1
250
コードの90%をAIが書く世界で何が待っているのか / What awaits us in a world where 90% of the code is written by AI
rkaga
50
32k
たった 1 枚の PHP ファイルで実装する MCP サーバ / MCP Server with Vanilla PHP
okashoi
1
230
Google Agent Development Kit でLINE Botを作ってみた
ymd65536
2
220
Azure AI Foundryではじめてのマルチエージェントワークフロー
seosoft
0
160
WebViewの現在地 - SwiftUI時代のWebKit - / The Current State Of WebView
marcy731
0
110
ペアプロ × 生成AI 現場での実践と課題について / generative-ai-in-pair-programming
codmoninc
1
14k
AWS CDKの推しポイント 〜CloudFormationと比較してみた〜
akihisaikeda
3
320
Hypervel - A Coroutine Framework for Laravel Artisans
albertcht
1
110
「Cursor/Devin全社導入の理想と現実」のその後
saitoryc
0
760
iOS 26にアップデートすると実機でのHot Reloadができない?
umigishiaoi
0
120
Featured
See All Featured
Typedesign – Prime Four
hannesfritz
42
2.7k
Stop Working from a Prison Cell
hatefulcrawdad
270
21k
How to train your dragon (web standard)
notwaldorf
94
6.1k
The Language of Interfaces
destraynor
158
25k
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
125
52k
Into the Great Unknown - MozCon
thekraken
39
1.9k
Building Flexible Design Systems
yeseniaperezcruz
328
39k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
181
53k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
107
19k
How GitHub (no longer) Works
holman
314
140k
Faster Mobile Websites
deanohume
307
31k
Transcript
jgs CSE 240 Introduction to Programming Languages Lecture 11: malloc
and free Dr. Javier Gonzalez-Sanchez javiergs@asu.edu 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.
javiergs@asu.edu 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.