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
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
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
CSC307 Lecture 21
javiergs
PRO
0
68
CSC307 Lecture 17
javiergs
PRO
0
340
CSC305 Lecture 18
javiergs
PRO
0
380
final project
javiergs
PRO
0
130
CSC305 Lecture 18
javiergs
PRO
0
100
CSC307_L17_mqtt.pdf
javiergs
PRO
0
71
UP Lecture 28
javiergs
PRO
0
62
CSC307_L99_TDD.pdf
javiergs
PRO
0
71
CSC307_L99_TDD.pdf
javiergs
PRO
0
67
Other Decks in Programming
See All in Programming
夏だ!祭りだ!祭りとはドメインモデリングでは?
ryugen04
0
350
30年振りにコンパイラの定数整数除算を改善した
herumi
7
3.5k
【デモ】Kiroで体験する仕様駆動開発|設計からコーディングまでAIと進める開発フロー
cmkudo
0
310
使いながら育てる Claude Code — 開発フローの1コマンド化 × 繰り返し指摘の自動仕組み化
shiki_kakaku
0
1.9k
わからない話を追いかけたら、プログラミング言語を作る側にいた
ydah
3
530
今さら聞けない .NET CLI
htkym
0
210
不幸な GC
chencmd
0
480
【QA Test Talk Vol.8】AI-DLC による Whole Team Approach の加速
pkshadeck
PRO
0
220
複数の Claude Code が"放置"されてしまう問題をCLI ダッシュボードを自作して解決した話
sumihiro3
1
710
ソフトウェアラスタライザ
fadis
1
280
AI Readyの正体はデータマネジメントだ メダリオン2.0の最前線
freee
PRO
0
350
TSX の <Hoge<Fuga>> という構文に驚いた話 / tsx-type-argument-syntax
kanaru0928
0
240
Featured
See All Featured
The Power of CSS Pseudo Elements
geoffreycrofte
82
6.5k
Learning to Love Humans: Emotional Interface Design
aarron
275
41k
HTML-Aware ERB: The Path to Reactive Rendering @ RubyCon 2026, Rimini, Italy
marcoroth
3
470
DevOps and Value Stream Thinking: Enabling flow, efficiency and business value
helenjbeal
1
360
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.8k
ラッコキーワード サービス紹介資料
rakko
1
4.5M
Accessibility Awareness
sabderemane
1
180
The Curse of the Amulet
leimatthew05
2
14k
We Analyzed 250 Million AI Search Results: Here's What I Found
joshbly
1
1.8k
Paper Plane
katiecoart
PRO
2
53k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
162
16k
Building Flexible Design Systems
yeseniaperezcruz
330
40k
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.