1 of 237

2 of 237

This is CS50

  • If you'd like to attend CS50 Lunch this Fri 10/3 at 1:15pm, RSVP at cs50.ly/lunch!
  • On today's snack menu, clementines 🍊 and fruit snacks 🍬.
  • Do say hi or ask questions during break or after class!
    • What do today's binary bulbs spell?

3 of 237

4 of 237

5 of 237

6 of 237

7 of 237

8 of 237

9 of 237

10 of 237

11 of 237

12 of 237

13 of 237

pixel art

14 of 237

15 of 237

16 of 237

17 of 237

18 of 237

19 of 237

RGB

20 of 237

21 of 237

22 of 237

23 of 237

24 of 237

25 of 237

0 1 2 3 4 5 6 7 8 9 A B C D E F

26 of 237

0 1 2 3 4 5 6 7 8 9 A B C D E F

27 of 237

0 1 2 3 4 5 6 7 8 9 a b c d e f

28 of 237

0 1 2 3 4 5 6 7 8 9 A B C D E F

29 of 237

hexadecimal

30 of 237

base-16

31 of 237

# #

161

160

32 of 237

# #

16

1

33 of 237

00

16

1

34 of 237

01

16

1

35 of 237

02

16

1

36 of 237

03

16

1

37 of 237

04

16

1

38 of 237

05

16

1

39 of 237

06

16

1

40 of 237

07

16

1

41 of 237

08

16

1

42 of 237

09

16

1

43 of 237

0A

16

1

44 of 237

0B

16

1

45 of 237

0C

16

1

46 of 237

0D

16

1

47 of 237

0E

16

1

48 of 237

0F

16

1

49 of 237

10

16

1

50 of 237

11

16

1

51 of 237

12

16

1

52 of 237

13

16

1

53 of 237

14

16

1

54 of 237

16

1

55 of 237

FF

16

1

56 of 237

FF

16

1

16 × F

1 × F

+

57 of 237

FF

16

1

16 × 15

1 × 15

+

58 of 237

FF

16

1

240

15

+

59 of 237

FF

16

1

255

60 of 237

FF

61 of 237

F F

62 of 237

1111 1111

63 of 237

64 of 237

0

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

65 of 237

0

1

2

3

4

5

6

7

8

9

A

B

C

D

E

F

10

11

12

13

14

15

16

17

18

19

1A

1B

1C

1D

1E

1F

66 of 237

0

1

2

3

4

5

6

7

8

9

A

B

C

D

E

F

10

11

12

13

14

15

16

17

18

19

1A

1B

1C

1D

1E

1F

67 of 237

0x0

0x1

0x2

0x3

0x4

0x5

0x6

0x7

0x8

0x9

0xA

0xB

0xC

0xD

0xE

0xF

0x10

0x11

0x12

0x13

0x14

0x15

0x16

0x17

0x18

0x19

0x1A

0x1B

0x1C

0x1D

0x1E

0x1F

68 of 237

int n = 50;

69 of 237

70 of 237

50

n

71 of 237

50

0x123

72 of 237

&

*

73 of 237

%p

74 of 237

pointers

75 of 237

int n = 50;

int *p = &n;

76 of 237

int n = 50;

int *p = &n;

77 of 237

int n = 50;

int* p = &n;

78 of 237

int n = 50;

int * p = &n;

79 of 237

int n = 50;

int *p = &n;

80 of 237

81 of 237

50

n

82 of 237

50

0x123

83 of 237

0x123

p

50

0x123

84 of 237

0x123

p

50

0x123

85 of 237

p

50

0x123

86 of 237

string

87 of 237

string s = "HI!";

88 of 237

H

I

!

\0

89 of 237

H

s[0]

I

s[1]

!

s[2]

\0

s[3]

90 of 237

H

0x123

I

0x124

!

0x125

\0

0x126

91 of 237

s

H

0x123

I

0x124

!

0x125

\0

0x126

92 of 237

0x123

s

H

0x123

I

0x124

!

0x125

\0

0x126

93 of 237

s

H

0x123

I

0x124

!

0x125

\0

0x126

0x127

94 of 237

string s = "HI!";

95 of 237

string s = "HI!";

96 of 237

char *s = "HI!";

97 of 237

typedef struct

{

string name;

string number;

} person;

98 of 237

typedef struct

{

string name;

string number;

} person;

99 of 237

typedef struct

{

string name;

string number;

} person;

100 of 237

typedef struct

{

string name;

string number;

} person;

101 of 237

typedef

102 of 237

typedef int

103 of 237

typedef int integer;

104 of 237

typedef

105 of 237

typedef char *

106 of 237

typedef char *string;

107 of 237

typedef char *string;

108 of 237

typedef uint8_t BYTE;

109 of 237

typedef uint8_t BYTE;

110 of 237

typedef uint8_t BYTE;

111 of 237

cs50.h

112 of 237

pointer arithmetic

113 of 237

0x123

s

H

0x123

I

0x124

!

0x125

\0

0x126

114 of 237

115 of 237

50

i

50

j

116 of 237

strcmp

117 of 237

118 of 237

s

119 of 237

s

H

I

!

\0

120 of 237

s

H

0x123

I

0x124

!

0x125

\0

0x126

121 of 237

0x123

s

H

0x123

I

0x124

!

0x125

\0

0x126

122 of 237

0x123

s

t

H

0x123

I

0x124

!

0x125

\0

0x126

123 of 237

0x123

s

t

H

0x123

I

0x124

!

0x125

\0

0x126

H

I

!

\0

124 of 237

0x123

s

t

H

0x123

I

0x124

!

0x125

\0

0x126

H

0x456

I

0x457

!

0x458

\0

0x459

125 of 237

0x123

s

0x456

t

H

0x123

I

0x124

!

0x125

\0

0x126

H

0x456

I

0x457

!

0x458

\0

0x459

126 of 237

s

t

H

0x123

I

0x124

!

0x125

\0

0x126

H

0x456

I

0x457

!

0x458

\0

0x459

127 of 237

128 of 237

s

129 of 237

s

h

i

!

\0

130 of 237

s

h

0x123

i

0x124

!

0x125

\0

0x126

131 of 237

0x123

s

h

0x123

i

0x124

!

0x125

\0

0x126

132 of 237

0x123

s

t

h

0x123

i

0x124

!

0x125

\0

0x126

133 of 237

0x123

s

0x123

t

h

0x123

i

0x124

!

0x125

\0

0x126

134 of 237

s

t

h

0x123

i

0x124

!

0x125

\0

0x126

135 of 237

s

t

H

0x123

i

0x124

!

0x125

\0

0x126

136 of 237

malloc

free

137 of 237

s

h

0x123

i

0x124

!

0x125

\0

0x126

138 of 237

s

t

h

0x123

i

0x124

!

0x125

\0

0x126

139 of 237

s

t

h

0x123

i

0x124

!

0x125

\0

0x126

0x456

0x457

0x458

0x459

140 of 237

s

t

h

0x123

i

0x124

!

0x125

\0

0x126

0x456

0x457

0x458

0x459

141 of 237

s

t

h

0x123

i

0x124

!

0x125

\0

0x126

h

0x456

0x457

0x458

0x459

142 of 237

s

t

h

0x123

i

0x124

!

0x125

\0

0x126

h

0x456

i

0x457

0x458

0x459

143 of 237

s

t

h

0x123

i

0x124

!

0x125

\0

0x126

h

0x456

i

0x457

!

0x458

0x459

144 of 237

s

t

h

0x123

i

0x124

!

0x125

\0

0x126

h

0x456

i

0x457

!

0x458

\0

0x459

145 of 237

s

t

h

0x123

i

0x124

!

0x125

\0

0x126

H

0x456

i

0x457

!

0x458

\0

0x459

146 of 237

NULL

147 of 237

148 of 237

149 of 237

valgrind

150 of 237

garbage values

151 of 237

int main(void)

{

int *x;

int *y;

x = malloc(sizeof(int));

*x = 42;

*y = 13;

y = x;

*y = 13;

}

152 of 237

int main(void)

{

int *x;

int *y;

x = malloc(sizeof(int));

*x = 42;

*y = 13;

y = x;

*y = 13;

}

153 of 237

int main(void)

{

int *x;

int *y;

x = malloc(sizeof(int));

*x = 42;

*y = 13;

y = x;

*y = 13;

}

154 of 237

int main(void)

{

int *x;

int *y;

x = malloc(sizeof(int));

*x = 42;

*y = 13;

y = x;

*y = 13;

}

155 of 237

int main(void)

{

int *x;

int *y;

x = malloc(sizeof(int));

*x = 42;

*y = 13;

y = x;

*y = 13;

}

156 of 237

int main(void)

{

int *x;

int *y;

x = malloc(sizeof(int));

*x = 42;

*y = 13;

y = x;

*y = 13;

}

157 of 237

int main(void)

{

int *x;

int *y;

x = malloc(sizeof(int));

*x = 42;

*y = 13;

y = x;

*y = 13;

}

158 of 237

int main(void)

{

int *x;

int *y;

x = malloc(sizeof(int));

*x = 42;

*y = 13;

y = x;

*y = 13;

}

159 of 237

160 of 237

void swap(int a, int b)

{

}

161 of 237

void swap(int a, int b)

{

int tmp = a;

a = b;

b = tmp;

}

162 of 237

void swap(int a, int b)

{

int tmp = a;

a = b;

b = tmp;

}

163 of 237

scope

164 of 237

passing by value

165 of 237

166 of 237

167 of 237

168 of 237

169 of 237

stack

170 of 237

machine code

stack

171 of 237

machine code

globals

heap

stack

172 of 237

machine code

globals

heap

stack

173 of 237

machine code

globals

heap

stack

174 of 237

machine code

globals

heap

stack

175 of 237

machine code

globals

heap

stack

176 of 237

stack

177 of 237

void swap(int a, int b)

{

int tmp = a;

a = b;

b = tmp;

}

178 of 237

main

179 of 237

main

swap

180 of 237

main

181 of 237

x

y

182 of 237

int x = 1;

int y = 2;

1

x

2

y

183 of 237

swap(x, y);

1

x

2

y

swap

184 of 237

swap(x, y);

a

b

tmp

1

x

2

y

185 of 237

void swap(int a, int b);

1

a

2

b

tmp

1

x

2

y

186 of 237

int tmp = a;

a = b;

b = tmp;

1

a

2

b

tmp

1

x

2

y

187 of 237

int tmp = a;

a = b;

b = tmp;

1

a

2

b

1

tmp

1

x

2

y

188 of 237

int tmp = a;

a = b;

b = tmp;

2

a

2

b

1

tmp

1

x

2

y

189 of 237

int tmp = a;

a = b;

b = tmp;

2

a

1

b

1

tmp

1

x

2

y

190 of 237

2

a

1

b

1

tmp

1

x

2

y

191 of 237

1

x

2

y

192 of 237

passing by reference

193 of 237

void swap(int a, int b)

{

int tmp = a;

a = b;

b = tmp;

}

194 of 237

void swap(int *a, int *b)

{

int tmp = *a;

*a = *b;

*b = tmp;

}

195 of 237

void swap(int *a, int *b)

{

int tmp = *a;

*a = *b;

*b = tmp;

}

196 of 237

1

x

2

y

197 of 237

swap(x, y);

1

x

2

y

swap

198 of 237

swap(x, y);

a

b

tmp

1

x

2

y

199 of 237

void swap(int *a, int *b);

a

b

tmp

1

x

2

y

200 of 237

int tmp = *a;

*a = *b;

*b = tmp;

a

b

tmp

1

x

2

y

201 of 237

int tmp = *a;

*a = *b;

*b = tmp;

a

b

1

tmp

1

x

2

y

202 of 237

int tmp = *a;

*a = *b;

*b = tmp;

a

b

1

tmp

2

x

2

y

203 of 237

int tmp = *a;

*a = *b;

*b = tmp;

a

b

1

tmp

2

x

1

y

204 of 237

a

b

1

tmp

2

x

1

y

205 of 237

2

x

1

y

206 of 237

void swap(int a, int b)

{

int tmp = a;

a = b;

b = tmp;

}

207 of 237

void swap(int *a, int *b)

{

int tmp = *a;

*a = *b;

*b = tmp;

}

208 of 237

machine code

globals

heap

stack

209 of 237

heap

stack

210 of 237

heap overflow

stack overflow

211 of 237

buffer overflow

212 of 237

get_char

get_double

get_float

get_int

get_long

get_string

...

213 of 237

get_int

214 of 237

scanf

215 of 237

216 of 237

217 of 237

50

n

218 of 237

219 of 237

220 of 237

s

221 of 237

s

222 of 237

s

223 of 237

224 of 237

225 of 237

s

226 of 237

file I/O

227 of 237

fopen

fclose

fprintf

fscanf

fread

fwrite

fseek

228 of 237

229 of 237

BMP

230 of 237

231 of 237

232 of 237

233 of 237

234 of 237

235 of 237

236 of 237

237 of 237