1 of 207

This is CS50

2 of 207

3 of 207

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

4 of 207

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

5 of 207

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

6 of 207

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

7 of 207

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

8 of 207

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

9 of 207

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

10 of 207

base-16

11 of 207

hexadecimal

12 of 207

11111111

22

21

20

25

24

23

27

26

13 of 207

11111111

4

2

1

32

16

8

128

64

14 of 207

11111111

4

2

1

32

16

8

128

64

128 × 1 + 64 × 1 + 32 × 1 + 16 × 1 + 8 × 1 + 4 × 1 + 2 × 1 + 1 × 1

15 of 207

11111111

4

2

1

32

16

8

128

64

255

16 of 207

255

102

101

100

17 of 207

255

100

10

1

18 of 207

# #

161

160

19 of 207

# #

16

1

20 of 207

00

16

1

21 of 207

01

16

1

22 of 207

02

16

1

23 of 207

03

16

1

24 of 207

04

16

1

25 of 207

05

16

1

26 of 207

06

16

1

27 of 207

07

16

1

28 of 207

08

16

1

29 of 207

09

16

1

30 of 207

0A

16

1

31 of 207

0B

16

1

32 of 207

0C

16

1

33 of 207

0D

16

1

34 of 207

0E

16

1

35 of 207

0F

16

1

36 of 207

10

16

1

37 of 207

16

1

38 of 207

FF

16

1

39 of 207

FF

16

1

16 × F

1 × F

+

40 of 207

FF

16

1

16 × 15

1 × 15

+

41 of 207

FF

16

1

240

15

+

42 of 207

FF

16

1

255

43 of 207

11111111

4

2

1

32

16

8

128

64

255

44 of 207

11111111

45 of 207

1111 1111

46 of 207

F F

47 of 207

RGB

48 of 207

49 of 207

72

73

33

50 of 207

48

49

21

51 of 207

0x48

0x49

0x21

52 of 207

53 of 207

54 of 207

55 of 207

56 of 207

57 of 207

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

58 of 207

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

59 of 207

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

60 of 207

int n = 50;

61 of 207

62 of 207

50

n

63 of 207

50

0x12345678

64 of 207

&

*

65 of 207

pointers

66 of 207

int n = 50;

int *p = &n;

67 of 207

68 of 207

50

n

69 of 207

50

0x123

70 of 207

0x123

p

50

0x123

71 of 207

0x123

p

50

0x123

72 of 207

p

50

0x123

73 of 207

string

74 of 207

string s = "HI!";

75 of 207

H

I

!

\0

76 of 207

H

s[0]

I

s[1]

!

s[2]

\0

s[3]

77 of 207

H

0x123

I

0x124

!

0x125

\0

0x126

78 of 207

0x123

s

H

0x123

I

0x124

!

0x125

\0

0x126

79 of 207

s

H

0x123

I

0x124

!

0x125

\0

0x126

0x127

80 of 207

s

E

0x123

M

0x124

M

0x125

\0

0x126

0x127

81 of 207

s

E

0x123

M

0x124

A

0x125

00000000

0x126

0x127

82 of 207

string s = "HI!";

83 of 207

char *s = "HI!";

84 of 207

char *s = "HI!";

85 of 207

typedef struct

{

string name;

string number;

}

person;

86 of 207

typedef struct

{

string name;

string number;

}

person;

87 of 207

typedef char *string;

88 of 207

pointer arithmetic

89 of 207

string

90 of 207

char *

91 of 207

92 of 207

s

93 of 207

s

H

I

!

\0

94 of 207

s

H

0x123

I

0x124

!

0x125

\0

0x126

95 of 207

0x123

s

H

0x123

I

0x124

!

0x125

\0

0x126

96 of 207

0x123

s

t

H

0x123

I

0x124

!

0x125

\0

0x126

97 of 207

0x123

s

t

H

0x123

I

0x124

!

0x125

\0

0x126

H

I

!

\0

98 of 207

0x123

s

t

H

0x123

I

0x124

!

0x125

\0

0x126

H

0x456

I

0x457

!

0x498

\0

0x459

99 of 207

0x123

s

0x456

t

H

0x123

I

0x124

!

0x125

\0

0x126

H

0x456

I

0x457

!

0x498

\0

0x459

100 of 207

s

t

H

0x123

I

0x124

!

0x125

\0

0x126

H

0x456

I

0x457

!

0x498

\0

0x459

101 of 207

char *

102 of 207

103 of 207

s

104 of 207

s

h

i

!

\0

105 of 207

s

h

0x123

i

0x124

!

0x125

\0

0x126

106 of 207

0x123

s

h

0x123

i

0x124

!

0x125

\0

0x126

107 of 207

0x123

s

t

h

0x123

i

0x124

!

0x125

\0

0x126

108 of 207

0x123

s

0x123

t

h

0x123

i

0x124

!

0x125

\0

0x126

109 of 207

s

t

h

0x123

i

0x124

!

0x125

\0

0x126

110 of 207

s

t

H

0x123

i

0x124

!

0x125

\0

0x126

111 of 207

malloc

free

112 of 207

s

h

0x123

i

0x124

!

0x125

\0

0x126

113 of 207

s

t

h

0x123

i

0x124

!

0x125

\0

0x126

114 of 207

s

t

h

0x123

i

0x124

!

0x125

\0

0x126

0x456

0x457

0x458

0x459

115 of 207

s

t

h

0x123

i

0x124

!

0x125

\0

0x126

0x456

0x457

0x458

0x459

116 of 207

s

t

h

0x123

i

0x124

!

0x125

\0

0x126

h

0x456

0x457

0x458

0x459

117 of 207

s

t

h

0x123

i

0x124

!

0x125

\0

0x126

h

0x456

i

0x457

0x458

0x459

118 of 207

s

t

h

0x123

i

0x124

!

0x125

\0

0x126

h

0x456

i

0x457

!

0x458

0x459

119 of 207

s

t

h

0x123

i

0x124

!

0x125

\0

0x126

h

0x456

i

0x457

!

0x458

\0

0x459

120 of 207

s

t

h

0x123

i

0x124

!

0x125

\0

0x126

H

0x456

i

0x457

!

0x458

\0

0x459

121 of 207

valgrind

122 of 207

int main(void)

{

int *x;

int *y;

x = malloc(sizeof(int));

*x = 42;

*y = 13;

y = x;

*y = 13;

}

123 of 207

int main(void)

{

int *x;

int *y;

x = malloc(sizeof(int));

*x = 42;

*y = 13;

y = x;

*y = 13;

}

124 of 207

int main(void)

{

int *x;

int *y;

x = malloc(sizeof(int));

*x = 42;

*y = 13;

y = x;

*y = 13;

}

125 of 207

int main(void)

{

int *x;

int *y;

x = malloc(sizeof(int));

*x = 42;

*y = 13;

y = x;

*y = 13;

}

126 of 207

int main(void)

{

int *x;

int *y;

x = malloc(sizeof(int));

*x = 42;

*y = 13;

y = x;

*y = 13;

}

127 of 207

int main(void)

{

int *x;

int *y;

x = malloc(sizeof(int));

*x = 42;

*y = 13;

y = x;

*y = 13;

}

128 of 207

int main(void)

{

int *x;

int *y;

x = malloc(sizeof(int));

*x = 42;

*y = 13;

y = x;

*y = 13;

}

129 of 207

130 of 207

garbage values

131 of 207

void swap(int a, int b)

{

}

132 of 207

void swap(int a, int b)

{

int tmp = a;

a = b;

b = tmp;

}

133 of 207

void swap(int a, int b)

{

int tmp = a;

a = b;

b = tmp;

}

134 of 207

135 of 207

136 of 207

137 of 207

138 of 207

stack

139 of 207

machine code

stack

140 of 207

machine code

globals

heap

stack

141 of 207

machine code

globals

heap

stack

142 of 207

machine code

globals

heap

stack

143 of 207

machine code

globals

heap

stack

144 of 207

machine code

globals

heap

stack

145 of 207

stack

146 of 207

void swap(int a, int b)

{

int tmp = a;

a = b;

b = tmp;

}

147 of 207

main

148 of 207

main

swap

149 of 207

main

150 of 207

x

y

151 of 207

1

x

2

y

152 of 207

1

x

2

y

swap

153 of 207

a

b

tmp

1

x

2

y

154 of 207

1

a

2

b

tmp

1

x

2

y

155 of 207

int tmp = a;

a = b;

b = tmp;

1

a

2

b

tmp

1

x

2

y

156 of 207

int tmp = a;

a = b;

b = tmp;

1

a

2

b

1

tmp

1

x

2

y

157 of 207

int tmp = a;

a = b;

b = tmp;

2

a

2

b

1

tmp

1

x

2

y

158 of 207

int tmp = a;

a = b;

b = tmp;

2

a

1

b

1

tmp

1

x

2

y

159 of 207

2

a

1

b

1

tmp

1

x

2

y

160 of 207

1

x

2

y

161 of 207

void swap(int a, int b)

{

int tmp = a;

a = b;

b = tmp;

}

162 of 207

void swap(int *a, int *b)

{

int tmp = *a;

*a = *b;

*b = tmp;

}

163 of 207

1

x

2

y

164 of 207

a

b

tmp

1

x

2

y

165 of 207

int tmp = *a;

*a = *b;

*b = tmp;

a

b

tmp

1

x

2

y

166 of 207

int tmp = *a;

*a = *b;

*b = tmp;

a

b

1

tmp

1

x

2

y

167 of 207

int tmp = *a;

*a = *b;

*b = tmp;

a

b

1

tmp

2

x

2

y

168 of 207

int tmp = *a;

*a = *b;

*b = tmp;

a

b

1

tmp

2

x

1

y

169 of 207

a

b

1

tmp

2

x

1

y

170 of 207

2

x

1

y

171 of 207

void swap(int a, int b)

{

int tmp = a;

a = b;

b = tmp;

}

172 of 207

void swap(int *a, int *b)

{

int tmp = *a;

*a = *b;

*b = tmp;

}

173 of 207

machine code

globals

heap

stack

174 of 207

heap

stack

175 of 207

heap overflow

stack overflow

176 of 207

177 of 207

buffer overflow

178 of 207

get_char

get_double

get_float

get_int

get_long

get_string

...

179 of 207

scanf

...

180 of 207

file I/O

181 of 207

182 of 207

183 of 207

184 of 207

185 of 207

186 of 207

187 of 207

188 of 207

189 of 207

190 of 207

191 of 207

192 of 207

193 of 207

194 of 207

195 of 207

196 of 207

197 of 207

198 of 207

JPEG

199 of 207

BMP

200 of 207

201 of 207

202 of 207

203 of 207

204 of 207

205 of 207

206 of 207

207 of 207

This is CS50