Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Speaker Deck
PRO
Sign in
Sign up
for free
CSE240 Lecture 10
Javier Gonzalez
January 10, 2017
Programming
0
1.1k
CSE240 Lecture 10
Introduction to Programming Languages
Arrays and Pointers
(202009)
Javier Gonzalez
January 10, 2017
Tweet
Share
More Decks by Javier Gonzalez
See All by Javier Gonzalez
javiergs
0
520
javiergs
0
360
javiergs
0
330
javiergs
0
340
javiergs
0
260
javiergs
0
210
javiergs
0
130
javiergs
0
190
javiergs
0
480
Other Decks in Programming
See All in Programming
yotuba088
1
590
pirosikick
4
930
legalforce
PRO
0
610
grapecity_dev
0
170
grapecity_dev
0
170
larsrh
0
110
amaotone
15
7.8k
grapecity_dev
0
170
afilina
PRO
0
100
bkuhlmann
2
300
manfredsteyer
PRO
0
140
lovee
5
280
Featured
See All Featured
denniskardys
220
120k
keithpitt
401
20k
jacobian
255
20k
tenderlove
53
3.5k
geoffreycrofte
21
920
rocio
155
11k
sugarenia
233
850k
dougneiner
119
7.9k
paulrobertlloyd
71
3.6k
rasmusluckow
318
18k
erikaheidi
14
4.3k
orderedlist
PRO
328
36k
Transcript
jgs CSE 240 Introduction to Programming Languages Lecture 10: Arrays
and Pointers Javier Gonzalez-Sanchez javiergs@asu.edu PERALTA 230U Office Hours: By appointment
Javier Gonzalez-Sanchez | CSE240 | Spring 2018 | 2 jgs
Arrays are Pointers #include <stdio.h> void main() { int i = 0; char a[ ] = "Hello CSE 240"; printf("\n message: %s\n ", a); while (a[i] != '\0') { a[i] = *(a + i)+1; i++;} printf("\n message after encryption: %s\n ", a); char *q; q = a; while (*q != '\0') { *q = *q-1; q++;} printf("\n message after decryption: %s\n ", a); }
Javier Gonzalez-Sanchez | CSE240 | Spring 2018 | 3 jgs
Arrays are Pointers #include <stdio.h> void main() { int i = 0; char a[ ] = "Hello CSE 240"; printf("\n message: %s\n ", a); while (a[i] != '\0') { a[i] = *(a + i)+1; i++;} printf("\n message after encryption: %s\n ", a); char *q; q = a; while (*q != '\0') { *q = *q-1; q++;} printf("\n message after decryption: %s\n ", a); } a[i] = *(a + i)+ 1 a[i] = a[i]+ 1 *(a+i) = a[i]+ 1 *(a+i) = *(a+i)+ 1
Javier Gonzalez-Sanchez | CSE240 | Spring 2018 | 4 jgs
Arrays are Pointers #include <stdio.h> void main() { int i = 0; char a[ ] = "Hello CSE 240"; printf("\n message: %s\n ", a); while (a[i] != '\0') { a[i] = *(a + i)+1; i++;} printf("\n message after encryption: %s\n ", a); char *q; q = a; while (*q != '\0') { *q = *q-1; q++;} printf("\n message after decryption: %s\n ", a); }
Javier Gonzalez-Sanchez | CSE240 | Spring 2018 | 5 jgs
Arrays are Pointers #include <stdio.h> void main() { int i = 0; char a[ ] = "Hello CSE 240"; printf("\n message: %s\n ", a); while (a[i] != '\0') { a[i] = *(a + i)+1; i++;} printf("\n message after encryption: %s\n ", a); char *q; q = a; while (*q != '\0') { *q = *q-1; q++;} printf("\n message after decryption: %s\n ", a); } 0x48 a 0x44 H 0x48 e l l ... 0x48 q 0x94
Javier Gonzalez-Sanchez | CSE240 | Spring 2018 | 6 jgs
Arrays are Pointers #include <stdio.h> void main() { int i = 0; char a[ ] = "Hello CSE 240"; printf("\n message: %s\n ", a); while (a[i] != '\0') { a[i] = *(a + i)+1; i++;} printf("\n message after encryption: %s\n ", a); char *q; q = a; while (*q != '\0') { *q = *q-1; q++;} printf("\n message after decryption: %s\n ", a); }
Javier Gonzalez-Sanchez | CSE240 | Spring 2018 | 7 jgs
string.h library
jgs Test yourselves
Javier Gonzalez-Sanchez | CSE240 | Spring 2018 | 9 jgs
1
Javier Gonzalez-Sanchez | CSE240 | Spring 2018 | 10 jgs
2
Javier Gonzalez-Sanchez | CSE240 | Spring 2018 | 11 jgs
3
Javier Gonzalez-Sanchez | CSE240 | Spring 2018 | 12 jgs
4
Javier Gonzalez-Sanchez | CSE240 | Spring 2018 | 13 jgs
5
jgs What about 2D arrays?
Javier Gonzalez-Sanchez | CSE240 | Spring 2018 | 15 jgs
Dynamic 2D Array
jgs CSE 240 Introduction to Programming Languages Javier Gonzalez-Sanchez javiergs@asu.edu
Spring 2018 Disclaimer. These slides can only be used as study material for the class CSE240 at ASU. They cannot be distributed or used for another purpose.