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
UP Lecture 25
javiergs
PRO
0
10
CSC486 Lecture 14
javiergs
PRO
0
150
CSC486 Lecture 13
javiergs
PRO
0
100
CSC486 Lecture 12
javiergs
PRO
0
100
CSC486 Lecture 11
javiergs
PRO
0
59
CSC486 Lecture 10
javiergs
PRO
1
99
CSC486 Lecture 08
javiergs
PRO
0
85
CSC486 Lecture 07
javiergs
PRO
0
140
CSC486 Lecture 06
javiergs
PRO
0
120
Other Decks in Programming
See All in Programming
2025年のz-index設計を考える
tak_dcxi
13
4.9k
Duke on CRaC with Jakarta EE
ivargrimstad
1
300
Storybookの情報をMCPサーバー化する
shota_tech
3
1.4k
Live Coding: Migrating an Application to Signals
manfredsteyer
PRO
0
120
The New Developer Workflow: How AI Transforms Ideas into Code
danielsogl
0
140
GitHub Copilot for Azureを使い倒したい
ymd65536
1
350
知識0からカンファレンスやってみたらこうなった!
syossan27
5
300
2025-04-25 GitHub Copilot Agent ライブデモ(スクリプト)
goataka
0
130
ASP.NETアプリケーションのモダナイゼーションについて
tomokusaba
0
280
Rubyの!メソッドをちゃんと理解する
alstrocrack
2
380
一緒に働きたくなるプログラマの思想 #QiitaConference
mu_zaru
84
21k
AWS Summit Hong Kong 2025: Reinventing Programming - How AI Transforms Our Enterprise Coding Approach
dwchiang
0
150
Featured
See All Featured
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
32
2.3k
Building Better People: How to give real-time feedback that sticks.
wjessup
368
19k
Being A Developer After 40
akosma
91
590k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
3.8k
Mobile First: as difficult as doing things right
swwweet
223
9.6k
Bootstrapping a Software Product
garrettdimon
PRO
307
110k
A designer walks into a library…
pauljervisheath
205
24k
4 Signs Your Business is Dying
shpigford
183
22k
Optimising Largest Contentful Paint
csswizardry
37
3.2k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
180
53k
How to Ace a Technical Interview
jacobian
276
23k
Learning to Love Humans: Emotional Interface Design
aarron
273
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.