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
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
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 15
javiergs
PRO
0
210
CSC364 Lecture 14
javiergs
PRO
0
110
CSC307 Lecture 14
javiergs
PRO
0
450
CSC307 Lecture 13
javiergs
PRO
0
310
CSC364 Lecture 13
javiergs
PRO
0
94
CSC364 Lecture 12
javiergs
PRO
0
82
CSC307 Lecture 12
javiergs
PRO
0
450
CSC307 Lecture 11
javiergs
PRO
0
580
CSC307 Lecture 10
javiergs
PRO
1
690
Other Decks in Programming
See All in Programming
LangChain4jとは一味違うLangChain4j-CDI
kazumura
1
130
RAGでハマりがちな"Excelの罠"を、データの構造化で突破する
harumiweb
8
2.3k
24時間止められないシステムを守る-医療ITにおけるランサムウェア対策の実際
koukimiura
2
180
コーディングルールの鮮度を保ちたい / keep-fresh-go-internal-conventions
handlename
0
140
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
340
受け入れテスト駆動開発(ATDD)×AI駆動開発 AI時代のATDDの取り組み方を考える
kztakasaki
2
510
「やめとこ」がなくなった — 1月にZennを始めて22本書いた AI共創開発のリアル
atani14
0
340
Rで始めるML・LLM活用入門
wakamatsu_takumu
0
140
Claude Code の Skill で複雑な既存仕様をすっきり整理しよう
yuichirokato
1
230
Go 1.26でのsliceのメモリアロケーション最適化 / Go 1.26 リリースパーティ #go126party
mazrean
1
330
nilとは何か 〜interfaceの構造とnil!=nilから理解する〜
kuro_kurorrr
3
1.6k
izumin5210のプロポーザルのネタ探し #tskaigi_msup
izumin5210
1
500
Featured
See All Featured
Fireside Chat
paigeccino
41
3.8k
Jamie Indigo - Trashchat’s Guide to Black Boxes: Technical SEO Tactics for LLMs
techseoconnect
PRO
0
78
What does AI have to do with Human Rights?
axbom
PRO
1
2k
Marketing Yourself as an Engineer | Alaka | Gurzu
gurzu
0
140
First, design no harm
axbom
PRO
2
1.1k
Designing Powerful Visuals for Engaging Learning
tmiket
0
250
Neural Spatial Audio Processing for Sound Field Analysis and Control
skoyamalab
0
200
For a Future-Friendly Web
brad_frost
183
10k
Product Roadmaps are Hard
iamctodd
PRO
55
12k
The Illustrated Children's Guide to Kubernetes
chrisshort
51
52k
Are puppies a ranking factor?
jonoalderson
1
3.1k
Mobile First: as difficult as doing things right
swwweet
225
10k
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.