1 of 152

This is CS50

2 of 152

3 of 152

4 of 152

This is CS50

5 of 152

#include <stdio.h>

int main(void)�{

printf("hello, world\n");

}

6 of 152

01111111 01000101 01001100 01000110 00000010 00000001 00000001 00000000�00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000�00000010 00000000 00111110 00000000 00000001 00000000 00000000 00000000�10110000 00000101 01000000 00000000 00000000 00000000 00000000 00000000�01000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000�11010000 00010011 00000000 00000000 00000000 00000000 00000000 00000000�00000000 00000000 00000000 00000000 01000000 00000000 00111000 00000000�00001001 00000000 01000000 00000000 00100100 00000000 00100001 00000000�00000110 00000000 00000000 00000000 00000101 00000000 00000000 00000000�01000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000�01000000 00000000 01000000 00000000 00000000 00000000 00000000 00000000�01000000 00000000 01000000 00000000 00000000 00000000 00000000 00000000�11111000 00000001 00000000 00000000 00000000 00000000 00000000 00000000�11111000 00000001 00000000 00000000 00000000 00000000 00000000 00000000�00001000 00000000 00000000 00000000 00000000 00000000 00000000 00000000�00000011 00000000 00000000 00000000 00000100 00000000 00000000 00000000�00111000 00000010 00000000 00000000 00000000 00000000 00000000 00000000�...

7 of 152

make hello

./hello

8 of 152

clang hello.c

./a.out

9 of 152

clang -o hello hello.c

./hello

10 of 152

#include <stdio.h>

int main(void)

{

printf("hello, world\n");

}

11 of 152

#include <cs50.h>

#include <stdio.h>

int main(void)

{

string name = get_string("What's your name? ");

printf("hello, %s\n", name);

}

12 of 152

clang -o hello hello.c -lcs50

./hello

13 of 152

make hello

./hello

14 of 152

compiling

15 of 152

preprocessing

compiling

assembling

linking

16 of 152

preprocessing

compiling

assembling

linking

17 of 152

#include <cs50.h>

#include <stdio.h>

int main(void)

{

string name = get_string("What's your name? ");

printf("hello, %s\n", name);

}

18 of 152

#include <cs50.h>

#include <stdio.h>

int main(void)

{

string name = get_string("What's your name? ");

printf("hello, %s\n", name);

}

19 of 152

string get_string(string prompt);

#include <stdio.h>

int main(void)

{

string name = get_string("What's your name? ");

printf("hello, %s\n", name);

}

20 of 152

string get_string(string prompt);

#include <stdio.h>

int main(void)

{

string name = get_string("What's your name? ");

printf("hello, %s\n", name);

}

21 of 152

string get_string(string prompt);

int printf(string format, ...);

int main(void)

{

string name = get_string("What's your name? ");

printf("hello, %s\n", name);

}

22 of 152

...

string get_string(string prompt);

int printf(string format, ...);

...

int main(void)

{

string name = get_string("What's your name? ");

printf("hello, %s\n", name);

}

23 of 152

preprocessing

compiling

assembling

linking

24 of 152

...

string get_string(string prompt);

int printf(string format, ...);

...

int main(void)

{

string name = get_string("What's your name? ");

printf("hello, %s\n", name);

}

25 of 152

...

main: # @main

.cfi_startproc

# BB#0:

pushq %rbp

.Ltmp0:

.cfi_def_cfa_offset 16

.Ltmp1:

.cfi_offset %rbp, -16

movq %rsp, %rbp

.Ltmp2:

.cfi_def_cfa_register %rbp

subq $16, %rsp

xorl %eax, %eax

movl %eax, %edi

movabsq $.L.str, %rsi

movb $0, %al

callq get_string

movabsq $.L.str.1, %rdi

movq %rax, -8(%rbp)

movq -8(%rbp), %rsi

movb $0, %al

callq printf

...

26 of 152

...

main: # @main

.cfi_startproc

# BB#0:

pushq %rbp

.Ltmp0:

.cfi_def_cfa_offset 16

.Ltmp1:

.cfi_offset %rbp, -16

movq %rsp, %rbp

.Ltmp2:

.cfi_def_cfa_register %rbp

subq $16, %rsp

xorl %eax, %eax

movl %eax, %edi

movabsq $.L.str, %rsi

movb $0, %al

callq get_string

movabsq $.L.str.1, %rdi

movq %rax, -8(%rbp)

movq -8(%rbp), %rsi

movb $0, %al

callq printf

...

27 of 152

...

main: # @main

.cfi_startproc

# BB#0:

pushq %rbp

.Ltmp0:

.cfi_def_cfa_offset 16

.Ltmp1:

.cfi_offset %rbp, -16

movq %rsp, %rbp

.Ltmp2:

.cfi_def_cfa_register %rbp

subq $16, %rsp

xorl %eax, %eax

movl %eax, %edi

movabsq $.L.str, %rsi

movb $0, %al

callq get_string

movabsq $.L.str.1, %rdi

movq %rax, -8(%rbp)

movq -8(%rbp), %rsi

movb $0, %al

callq printf

...

28 of 152

preprocessing

compiling

assembling

linking

29 of 152

...

main: # @main

.cfi_startproc

# BB#0:

pushq %rbp

.Ltmp0:

.cfi_def_cfa_offset 16

.Ltmp1:

.cfi_offset %rbp, -16

movq %rsp, %rbp

.Ltmp2:

.cfi_def_cfa_register %rbp

subq $16, %rsp

xorl %eax, %eax

movl %eax, %edi

movabsq $.L.str, %rsi

movb $0, %al

callq get_string

movabsq $.L.str.1, %rdi

movq %rax, -8(%rbp)

movq -8(%rbp), %rsi

movb $0, %al

callq printf

...

30 of 152

01111111010001010100110001000110

00000010000000010000000100000000

00000000000000000000000000000000

00000000000000000000000000000000

00000001000000000011111000000000

00000001000000000000000000000000

00000000000000000000000000000000

00000000000000000000000000000000

00000000000000000000000000000000

00000000000000000000000000000000

10100000000000100000000000000000

00000000000000000000000000000000

00000000000000000000000000000000

01000000000000000000000000000000

00000000000000000100000000000000

00001010000000000000000100000000

01010101010010001000100111100101

01001000100000111110110000010000

00110001110000001000100111000111

01001000101111100000000000000000

00000000000000000000000000000000

00000000000000001011000000000000

11101000000000000000000000000000

00000000010010001011111100000000

00000000000000000000000000000000

00000000000000000000000001001000

...

31 of 152

preprocessing

compiling

assembling

linking

32 of 152

#include <cs50.h>

#include <stdio.h>

int main(void)

{

string name = get_string("What's your name? ");

printf("hello, %s\n", name);

}

33 of 152

#include <cs50.h>

#include <stdio.h>

int main(void)

{

string name = get_string("What's your name? ");

printf("hello, %s\n", name);

}

34 of 152

#include <cs50.h>

#include <stdio.h>

int main(void)

{

string name = get_string("What's your name? ");

printf("hello, %s\n", name);

}

35 of 152

#include <cs50.h>

#include <stdio.h>

int main(void)

{

string name = get_string("What's your name? ");

printf("hello, %s\n", name);

}

36 of 152

hello.c

37 of 152

hello.c

cs50.c

38 of 152

hello.c

cs50.c

stdio.c

39 of 152

01111111010001010100110001000110

00000010000000010000000100000000

00000000000000000000000000000000

00000000000000000000000000000000

00000001000000000011111000000000

00000001000000000000000000000000

00000000000000000000000000000000

00000000000000000000000000000000

00000000000000000000000000000000

00000000000000000000000000000000

10100000000000100000000000000000

00000000000000000000000000000000

00000000000000000000000000000000

01000000000000000000000000000000

00000000000000000100000000000000

00001010000000000000000100000000

01010101010010001000100111100101

01001000100000111110110000010000

00110001110000001000100111000111

01001000101111100000000000000000

00000000000000000000000000000000

00000000000000001011000000000000

11101000000000000000000000000000

00000000010010001011111100000000

00000000000000000000000000000000

00000000000000000000000001001000

...

cs50.c

stdio.c

40 of 152

01111111010001010100110001000110

00000010000000010000000100000000

00000000000000000000000000000000

00000000000000000000000000000000

00000001000000000011111000000000

00000001000000000000000000000000

00000000000000000000000000000000

00000000000000000000000000000000

00000000000000000000000000000000

00000000000000000000000000000000

10100000000000100000000000000000

00000000000000000000000000000000

00000000000000000000000000000000

01000000000000000000000000000000

00000000000000000100000000000000

00001010000000000000000100000000

01010101010010001000100111100101

01001000100000111110110000010000

00110001110000001000100111000111

01001000101111100000000000000000

00000000000000000000000000000000

00000000000000001011000000000000

11101000000000000000000000000000

00000000010010001011111100000000

00000000000000000000000000000000

00000000000000000000000001001000

...

01111111010001010100110001000110

00000010000000010000000100000000

00000000000000000000000000000000

00000000000000000000000000000000

00000011000000000011111000000000

00000001000000000000000000000000

11000000000011110000000000000000

00000000000000000000000000000000

01000000000000000000000000000000

00000000000000000000000000000000

00101000001100100000000000000000

00000000000000000000000000000000

00000000000000000000000000000000

01000000000000000011100000000000

00000111000000000100000000000000

00011100000000000001100100000000

00000001000000000000000000000000

00000101000000000000000000000000

00000000000000000000000000000000

00000000000000000000000000000000

00000000000000000000000000000000

00000000000000000000000000000000

00000000000000000000000000000000

00000000000000000000000000000000

01011100001001010000000000000000

00000000000000000000000000000000

...

stdio.c

41 of 152

01111111010001010100110001000110

00000010000000010000000100000000

00000000000000000000000000000000

00000000000000000000000000000000

00000001000000000011111000000000

00000001000000000000000000000000

00000000000000000000000000000000

00000000000000000000000000000000

00000000000000000000000000000000

00000000000000000000000000000000

10100000000000100000000000000000

00000000000000000000000000000000

00000000000000000000000000000000

01000000000000000000000000000000

00000000000000000100000000000000

00001010000000000000000100000000

01010101010010001000100111100101

01001000100000111110110000010000

00110001110000001000100111000111

01001000101111100000000000000000

00000000000000000000000000000000

00000000000000001011000000000000

11101000000000000000000000000000

00000000010010001011111100000000

00000000000000000000000000000000

00000000000000000000000001001000

...

01111111010001010100110001000110

00000010000000010000000100000000

00000000000000000000000000000000

00000000000000000000000000000000

00000011000000000011111000000000

00000001000000000000000000000000

11000000000011110000000000000000

00000000000000000000000000000000

01000000000000000000000000000000

00000000000000000000000000000000

00101000001100100000000000000000

00000000000000000000000000000000

00000000000000000000000000000000

01000000000000000011100000000000

00000111000000000100000000000000

00011100000000000001100100000000

00000001000000000000000000000000

00000101000000000000000000000000

00000000000000000000000000000000

00000000000000000000000000000000

00000000000000000000000000000000

00000000000000000000000000000000

00000000000000000000000000000000

00000000000000000000000000000000

01011100001001010000000000000000

00000000000000000000000000000000

...

00101111011011000110100101100010

01100011001011100111001101101111

00101110001101100010000000101111

01110101011100110111001000101111

01101100011010010110001000101111

01111000001110000011011001011111

00110110001101000010110101101100

01101001011011100111010101111000

00101101011001110110111001110101

00101111011011000110100101100010

01100011010111110110111001101111

01101110011100110110100001100001

01110010011001010110010000101110

01100001001000000010000001000001

01010011010111110100111001000101

01000101010001000100010101000100

00100000001010000010000000101111

01101100011010010110001000101111

01111000001110000011011001011111

00110110001101000010110101101100

01101001011011100111010101111000

00101101011001110110111001110101

00101111011011000110010000101101

01101100011010010110111001110101

01111000001011010111100000111000

00110110001011010011011000110100

...

42 of 152

0111111101000101010011000100011000000010000000010000000100000000000000000000000000000000000000000000000000000000000000000000000000000001000000000011111000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010100000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000001000000000000000000101000000000000000010000000001010101010010001000100111100101010010001000001111101100000100000011000111000000100010011100011101001000101111100000000000000000000000000000000000000000000000000000000000000000101100000000000011101000000000000000000000000000000000000100100010111111000000000000000000000000000000000000000000000000000000000000000001001000...0111111101000101010011000100011000000010000000010000000100000000000000000000000000000000000000000000000000000000000000000000000000000011000000000011111000000000000000010000000000000000000000001100000000001111000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000101000001100100000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000011100000000000000001110000000001000000000000000001110000000000000110010000000000000001000000000000000000000000000001010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000101110000100101000000000000000000000000000000000000000000000000...0010111101101100011010010110001001100011001011100111001101101111001011100011011000100000001011110111010101110011011100100010111101101100011010010110001000101111011110000011100000110110010111110011011000110100001011010110110001101001011011100111010101111000001011010110011101101110011101010010111101101100011010010110001001100011010111110110111001101111011011100111001101101000011000010111001001100101011001000010111001100001001000000010000001000001010100110101111101001110010001010100010101000100010001010100010000100000001010000010000000101111011011000110100101100010001011110111100000111000001101100101111100110110001101000010110101101100011010010110111001110101011110000010110101100111011011100111010100101111011011000110010000101101011011000110100101101110011101010111100000101101011110000011100000110110001011010011011000110100...

43 of 152

preprocessing

compiling

assembling

linking

44 of 152

compiling

45 of 152

debugging

46 of 152

47 of 152

48 of 152

help50

style50

check50

49 of 152

help50

style50

check50

printf

50 of 152

help50

style50

check50

printf

debug50

51 of 152

help50

style50

check50

printf

debug50

ddb

52 of 152

types

53 of 152

bool

char

double

float

int

long

string

...

54 of 152

bool 1 byte

char 1 byte

double 8 bytes

float 4 bytes

int 4 bytes

long 8 bytes

string ? bytes

...

55 of 152

56 of 152

57 of 152

58 of 152

59 of 152

60 of 152

61 of 152

62 of 152

63 of 152

64 of 152

65 of 152

66 of 152

int score1 = 72;

int score2 = 73;

int score3 = 33;

67 of 152

68 of 152

72

score1

69 of 152

72

score1

73

score2

70 of 152

72

score1

73

score2

33

score3

71 of 152

00000000000000000000000001001000

score1

00000000000000000000000001001001

score2

00000000000000000000000000100001

score3

72 of 152

int score1 = 72;

int score2 = 73;

int score3 = 33;

73 of 152

arrays

74 of 152

int scores[3];

75 of 152

int scores[3];

scores[0] = 72;

scores[1] = 73;

scores[2] = 33;

76 of 152

72

scores[0]

73

scores[1]

33

scores[2]

77 of 152

constants

78 of 152

char c = '#';

79 of 152

80 of 152

#

c

81 of 152

35

c

82 of 152

00100011

c

83 of 152

char c1 = 'H';

char c2 = 'I';

char c3 = '!';

84 of 152

85 of 152

H

c1

I

c2

!

c3

86 of 152

72

c1

73

c2

33

c3

87 of 152

01001000

c1

01001001

c2

00100001

c3

88 of 152

string s = "HI!";

89 of 152

90 of 152

H

I

s

!

91 of 152

H

s[0]

I

s[1]

!

s[2]

92 of 152

H

s[0]

I

s[1]

!

s[2]

\0

s[3]

93 of 152

72

s[0]

73

s[1]

33

s[2]

0

s[3]

94 of 152

H

s

I

!

\0

95 of 152

NUL

96 of 152

string s = "HI!";

string t = "BYE!";

97 of 152

98 of 152

H

s

I

!

\0

99 of 152

H

s

I

!

\0

B

t

Y

E

!

\0

100 of 152

H

s[0]

I

s[1]

!

s[2]

\0

s[3]

B

t[0]

Y

t[1]

E

t[2]

!

t[3]

\0

t[4]

101 of 152

string words[2];

words[0] = "HI!";

words[1] = "BYE!";

102 of 152

H

words[0]

I

!

\0

B

words[1]

Y

E

!

\0

103 of 152

H

words[0][0]

I

words[0][1]

!

words[0][2]

\0

words[0][3]

B

words[1][0]

Y

words[1][1]

E

words[1][2]

!

words[1][3]

\0

words[1][4]

104 of 152

string

105 of 152

manual pages

106 of 152

command-line arguments

107 of 152

#include <stdio.h>

int main(void)�{

...

}

108 of 152

#include <stdio.h>

int main(void)�{

...

}

109 of 152

#include <stdio.h>

int main(int argc, string argv[])�{

...

}

110 of 152

exit status

111 of 152

#include <stdio.h>

int main(int argc, string argv[])�{

...

}

112 of 152

#include <stdio.h>

int main(int argc, string argv[])�{

...

}

113 of 152

#include <stdio.h>

int main(void)�{

...

}

114 of 152

readability

115 of 152

"Mr. and Mrs. Dursley, of number four, Privet Drive, were proud to say that they were perfectly normal, thank you very much. They were the last people you'd expect to be involved in anything strange or mysterious, because they just didn't hold with such nonsense..."

116 of 152

grade 7

117 of 152

"In computational linguistics, authorship attribution is the task of predicting the author of a document of unknown authorship. This task is generally performed via the analysis of stylometric features — particular characteristics of an author’s writing that can be used to identify his or her works in contrast with the works of other authors…"

118 of 152

grade 16

119 of 152

cryptography

120 of 152

input → 

→ output

121 of 152

plaintext → 

→ ciphertext

122 of 152

cipher

plaintext → 

→ ciphertext

123 of 152

cipher

plaintext → 

→ ciphertext

key → 

124 of 152

I LOVE YOU → 

?

1 → 

125 of 152

I L O V E Y O U 

126 of 152

73 L O V E Y O U 

127 of 152

73 76 O V E Y O U 

128 of 152

73 76 79 V E Y O U 

129 of 152

73 76 79 86 E Y O U 

130 of 152

73 76 79 86 69 Y O U 

131 of 152

73 76 79 86 69 89 O U 

132 of 152

73 76 79 86 69 89 79 U 

133 of 152

73 76 79 86 69 89 79 85

134 of 152

74 76 79 86 69 89 79 85

135 of 152

74 77 79 86 69 89 79 85

136 of 152

74 77 80 86 69 89 79 85

137 of 152

74 77 80 87 69 89 79 85

138 of 152

74 77 80 87 70 89 79 85

139 of 152

74 77 80 87 70 90 79 85

140 of 152

74 77 80 87 70 90 80 85

141 of 152

74 77 80 87 70 90 80 86

142 of 152

J 77 80 87 70 90 80 86

143 of 152

J M 80 87 70 90 80 86

144 of 152

J M P 87 70 90 80 86

145 of 152

J M P W 70 90 80 86

146 of 152

J M P W F 90 80 86

147 of 152

J M P W F Z 80 86

148 of 152

J M P W F Z P 86

149 of 152

J M P W F Z P V 

150 of 152

I LOVE YOU → 

J MPWF ZPV 

1 → 

151 of 152

152 of 152

This is CS50