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 05
javiergs
PRO
0
470
CSC364_L05_connection.pdf
javiergs
PRO
0
17
CSC364 Lecture 04
javiergs
PRO
0
79
CSC307 Lecture 04
javiergs
PRO
0
640
CSC307 Lecture 03
javiergs
PRO
1
480
CSC364 Lecture 03
javiergs
PRO
0
110
CSC307 Lecture 02
javiergs
PRO
1
760
CSC364 Lecture 02
javiergs
PRO
0
78
CSC307 Lecture 01
javiergs
PRO
0
670
Other Decks in Programming
See All in Programming
QAフローを最適化し、品質水準を満たしながらリリースまでの期間を最短化する #RSGT2026
shibayu36
2
3.6k
Deno Tunnel を使ってみた話
kamekyame
0
330
AgentCoreとHuman in the Loop
har1101
5
190
AI Agent の開発と運用を支える Durable Execution #AgentsInProd
izumin5210
7
2.1k
コマンドとリード間の連携に対する脅威分析フレームワーク
pandayumi
1
390
AIで開発はどれくらい加速したのか?AIエージェントによるコード生成を、現場の評価と研究開発の評価の両面からdeep diveしてみる
daisuketakeda
1
810
Findy AI+の開発、運用におけるMCP活用事例
starfish719
0
2.2k
0→1 フロントエンド開発 Tips🚀 #レバテックMeetup
bengo4com
0
500
LLM Observabilityによる 対話型音声AIアプリケーションの安定運用
gekko0114
2
380
TestingOsaka6_Ozono
o3
0
280
AI Agent Tool のためのバックエンドアーキテクチャを考える #encraft
izumin5210
6
1.7k
IFSによる形状設計/デモシーンの魅力 @ 慶應大学SFC
gam0022
0
190
Featured
See All Featured
A designer walks into a library…
pauljervisheath
210
24k
Measuring Dark Social's Impact On Conversion and Attribution
stephenakadiri
1
110
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
61k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
32
1.9k
How to Align SEO within the Product Triangle To Get Buy-In & Support - #RIMC
aleyda
1
1.4k
Balancing Empowerment & Direction
lara
5
850
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
5.8k
Lessons Learnt from Crawling 1000+ Websites
charlesmeaden
PRO
0
1k
Tips & Tricks on How to Get Your First Job In Tech
honzajavorek
0
420
Kristin Tynski - Automating Marketing Tasks With AI
techseoconnect
PRO
0
120
Unsuck your backbone
ammeep
671
58k
Public Speaking Without Barfing On Your Shoes - THAT 2023
reverentgeek
1
290
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.