1 of 206

2 of 206

This is CS50

  • Visit cs50.ly/screen to view projector on your laptop and ask questions via chat.
  • Today's snacks will be whoopie pies! 🟤
  • If coughing or not feeling well, do just leave early and watch online!
  • If you'd like to attend this week's (free) CS50 Lunch at Changsho (up Mass Ave) �on Fri 9/30 at 1:15pm, RSVP at cs50.ly/lunch!
  • Do say hi or ask questions during break or after class!

3 of 206

4 of 206

Happy Birthday to Xochi! 🥳

5 of 206

6 of 206

7 of 206

8 of 206

9 of 206

10 of 206

11 of 206

12 of 206

13 of 206

14 of 206

15 of 206

16 of 206

cs50.ly/art

17 of 206

RGB

18 of 206

19 of 206

20 of 206

21 of 206

22 of 206

23 of 206

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

24 of 206

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

25 of 206

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

26 of 206

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

27 of 206

hexadecimal

28 of 206

base-16

29 of 206

# #

161

160

30 of 206

# #

16

1

31 of 206

00

16

1

32 of 206

01

16

1

33 of 206

02

16

1

34 of 206

03

16

1

35 of 206

04

16

1

36 of 206

05

16

1

37 of 206

06

16

1

38 of 206

07

16

1

39 of 206

08

16

1

40 of 206

09

16

1

41 of 206

0A

16

1

42 of 206

0B

16

1

43 of 206

0C

16

1

44 of 206

0D

16

1

45 of 206

0E

16

1

46 of 206

0F

16

1

47 of 206

10

16

1

48 of 206

11

16

1

49 of 206

12

16

1

50 of 206

13

16

1

51 of 206

14

16

1

52 of 206

16

1

53 of 206

FF

16

1

54 of 206

FF

16

1

16 × F

1 × F

+

55 of 206

FF

16

1

16 × 15

1 × 15

+

56 of 206

FF

16

1

240

15

+

57 of 206

FF

16

1

255

58 of 206

F

59 of 206

1111

60 of 206

11111111

61 of 206

FF

62 of 206

63 of 206

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

64 of 206

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

65 of 206

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 206

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

67 of 206

int n = 50;

68 of 206

69 of 206

50

n

70 of 206

50

0x123

71 of 206

&

*

72 of 206

pointers

73 of 206

int n = 50;

int *p = &n;

74 of 206

75 of 206

50

n

76 of 206

50

0x123

77 of 206

0x123

p

50

0x123

78 of 206

0x123

p

50

0x123

79 of 206

p

50

0x123

80 of 206

string

81 of 206

string s = "HI!";

82 of 206

H

I

!

\0

83 of 206

H

s[0]

I

s[1]

!

s[2]

\0

s[3]

84 of 206

H

0x123

I

0x124

!

0x125

\0

0x126

85 of 206

0x123

s

H

0x123

I

0x124

!

0x125

\0

0x126

86 of 206

s

H

0x123

I

0x124

!

0x125

\0

0x126

0x127

87 of 206

string s = "HI!";

88 of 206

string s = "HI!";

89 of 206

char *s = "HI!";

90 of 206

typedef struct

{

string name;

string number;

}

person;

91 of 206

typedef struct

{

string name;

string number;

}

person;

92 of 206

typedef struct

{

string name;

string number;

}

person;

93 of 206

typedef struct

{

string name;

string number;

}

person;

94 of 206

typedef int integer;

95 of 206

typedef int integer;

96 of 206

typedef int integer;

97 of 206

typedef char *string;

98 of 206

typedef char *string;

99 of 206

typedef char *string;

100 of 206

cs50.h

101 of 206

pointer arithmetic

102 of 206

103 of 206

pointer arithmetic

104 of 206

string

105 of 206

char *

106 of 206

break

107 of 206

108 of 206

s

109 of 206

s

H

I

!

\0

110 of 206

s

H

0x123

I

0x124

!

0x125

\0

0x126

111 of 206

0x123

s

H

0x123

I

0x124

!

0x125

\0

0x126

112 of 206

0x123

s

t

H

0x123

I

0x124

!

0x125

\0

0x126

113 of 206

0x123

s

t

H

0x123

I

0x124

!

0x125

\0

0x126

H

I

!

\0

114 of 206

0x123

s

t

H

0x123

I

0x124

!

0x125

\0

0x126

H

0x456

I

0x457

!

0x458

\0

0x459

115 of 206

0x123

s

0x456

t

H

0x123

I

0x124

!

0x125

\0

0x126

H

0x456

I

0x457

!

0x458

\0

0x459

116 of 206

s

t

H

0x123

I

0x124

!

0x125

\0

0x126

H

0x456

I

0x457

!

0x458

\0

0x459

117 of 206

118 of 206

s

119 of 206

s

h

i

!

\0

120 of 206

s

h

0x123

i

0x124

!

0x125

\0

0x126

121 of 206

0x123

s

h

0x123

i

0x124

!

0x125

\0

0x126

122 of 206

0x123

s

t

h

0x123

i

0x124

!

0x125

\0

0x126

123 of 206

0x123

s

0x123

t

h

0x123

i

0x124

!

0x125

\0

0x126

124 of 206

s

t

h

0x123

i

0x124

!

0x125

\0

0x126

125 of 206

s

t

H

0x123

i

0x124

!

0x125

\0

0x126

126 of 206

malloc

free

127 of 206

s

h

0x123

i

0x124

!

0x125

\0

0x126

128 of 206

s

t

h

0x123

i

0x124

!

0x125

\0

0x126

129 of 206

s

t

h

0x123

i

0x124

!

0x125

\0

0x126

0x456

0x457

0x458

0x459

130 of 206

s

t

h

0x123

i

0x124

!

0x125

\0

0x126

0x456

0x457

0x458

0x459

131 of 206

s

t

h

0x123

i

0x124

!

0x125

\0

0x126

h

0x456

0x457

0x458

0x459

132 of 206

s

t

h

0x123

i

0x124

!

0x125

\0

0x126

h

0x456

i

0x457

0x458

0x459

133 of 206

s

t

h

0x123

i

0x124

!

0x125

\0

0x126

h

0x456

i

0x457

!

0x458

0x459

134 of 206

s

t

h

0x123

i

0x124

!

0x125

\0

0x126

h

0x456

i

0x457

!

0x458

\0

0x459

135 of 206

s

t

h

0x123

i

0x124

!

0x125

\0

0x126

H

0x456

i

0x457

!

0x458

\0

0x459

136 of 206

NULL

137 of 206

138 of 206

valgrind

139 of 206

garbage values

140 of 206

int main(void)

{

int *x;

int *y;

x = malloc(sizeof(int));

*x = 42;

*y = 13;

y = x;

*y = 13;

}

141 of 206

int main(void)

{

int *x;

int *y;

x = malloc(sizeof(int));

*x = 42;

*y = 13;

y = x;

*y = 13;

}

142 of 206

int main(void)

{

int *x;

int *y;

x = malloc(sizeof(int));

*x = 42;

*y = 13;

y = x;

*y = 13;

}

143 of 206

int main(void)

{

int *x;

int *y;

x = malloc(sizeof(int));

*x = 42;

*y = 13;

y = x;

*y = 13;

}

144 of 206

int main(void)

{

int *x;

int *y;

x = malloc(sizeof(int));

*x = 42;

*y = 13;

y = x;

*y = 13;

}

145 of 206

int main(void)

{

int *x;

int *y;

x = malloc(sizeof(int));

*x = 42;

*y = 13;

y = x;

*y = 13;

}

146 of 206

int main(void)

{

int *x;

int *y;

x = malloc(sizeof(int));

*x = 42;

*y = 13;

y = x;

*y = 13;

}

147 of 206

int main(void)

{

int *x;

int *y;

x = malloc(sizeof(int));

*x = 42;

*y = 13;

y = x;

*y = 13;

}

148 of 206

149 of 206

void swap(int a, int b)

{

}

150 of 206

void swap(int a, int b)

{

int tmp = a;

a = b;

b = tmp;

}

151 of 206

void swap(int a, int b)

{

int tmp = a;

a = b;

b = tmp;

}

152 of 206

scope

153 of 206

154 of 206

155 of 206

156 of 206

157 of 206

stack

158 of 206

machine code

stack

159 of 206

machine code

globals

heap

stack

160 of 206

machine code

globals

heap

stack

161 of 206

machine code

globals

heap

stack

162 of 206

machine code

globals

heap

stack

163 of 206

machine code

globals

heap

stack

164 of 206

stack

165 of 206

void swap(int a, int b)

{

int tmp = a;

a = b;

b = tmp;

}

166 of 206

main

167 of 206

main

swap

168 of 206

main

169 of 206

x

y

170 of 206

1

x

2

y

171 of 206

1

x

2

y

swap

172 of 206

a

b

tmp

1

x

2

y

173 of 206

1

a

2

b

tmp

1

x

2

y

174 of 206

int tmp = a;

a = b;

b = tmp;

1

a

2

b

tmp

1

x

2

y

175 of 206

int tmp = a;

a = b;

b = tmp;

1

a

2

b

1

tmp

1

x

2

y

176 of 206

int tmp = a;

a = b;

b = tmp;

2

a

2

b

1

tmp

1

x

2

y

177 of 206

int tmp = a;

a = b;

b = tmp;

2

a

1

b

1

tmp

1

x

2

y

178 of 206

2

a

1

b

1

tmp

1

x

2

y

179 of 206

1

x

2

y

180 of 206

void swap(int a, int b)

{

int tmp = a;

a = b;

b = tmp;

}

181 of 206

void swap(int *a, int *b)

{

int tmp = *a;

*a = *b;

*b = tmp;

}

182 of 206

1

x

2

y

183 of 206

a

b

tmp

1

x

2

y

184 of 206

int tmp = *a;

*a = *b;

*b = tmp;

a

b

tmp

1

x

2

y

185 of 206

int tmp = *a;

*a = *b;

*b = tmp;

a

b

1

tmp

1

x

2

y

186 of 206

int tmp = *a;

*a = *b;

*b = tmp;

a

b

1

tmp

2

x

2

y

187 of 206

int tmp = *a;

*a = *b;

*b = tmp;

a

b

1

tmp

2

x

1

y

188 of 206

a

b

1

tmp

2

x

1

y

189 of 206

2

x

1

y

190 of 206

void swap(int a, int b)

{

int tmp = a;

a = b;

b = tmp;

}

191 of 206

void swap(int *a, int *b)

{

int tmp = *a;

*a = *b;

*b = tmp;

}

192 of 206

machine code

globals

heap

stack

193 of 206

heap

stack

194 of 206

heap overflow

stack overflow

195 of 206

buffer overflow

196 of 206

get_char

get_double

get_float

get_int

get_long

get_string

...

197 of 206

scanf

...

198 of 206

file I/O

199 of 206

BMP

200 of 206

201 of 206

202 of 206

203 of 206

204 of 206

205 of 206

206 of 206