1 of 151

This is CS50

2 of 151

3 of 151

4 of 151

5 of 151

6 of 151

7 of 151

This is CS50

8 of 151

#include <stdio.h>

int main(void)�{

printf("hello, world");

}

9 of 151

10 of 151

#include <stdio.h>

int main(void)�{

printf("hello, world");

}

11 of 151

12 of 151

  • functions
  • conditions
  • Boolean expressions
  • loops
  • ...

13 of 151

correctness

14 of 151

design

15 of 151

style

16 of 151

#include <stdio.h>

int main(void)�{

printf("hello, world");

}

17 of 151

CS50 IDE

18 of 151

#include <stdio.h>

int main(void)�{

printf("hello, world");

}

19 of 151

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�...

20 of 151

input → 

→ output

21 of 151

22 of 151

source code → 

23 of 151

source code → 

machine code

24 of 151

compiler

source code → 

machine code

25 of 151

make hello

./hello

26 of 151

functions, arguments

27 of 151

printf("hello, world");

28 of 151

printf("hello, world");

29 of 151

printf("hello, world");

30 of 151

printf("hello, world");

31 of 151

printf("hello, world");

32 of 151

printf("hello, world");

33 of 151

functions

34 of 151

functions

arguments → 

35 of 151

side effects

36 of 151

return values, variables

37 of 151

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

printf("hello, %s", answer);

38 of 151

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

printf("hello, %s", answer);

39 of 151

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

printf("hello, %s", answer);

40 of 151

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

printf("hello, %s", answer);

41 of 151

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

printf("hello, %s", answer);

42 of 151

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

printf("hello, %s", answer);

43 of 151

functions

44 of 151

functions

arguments → 

45 of 151

functions

arguments → 

return value

46 of 151

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

printf("hello, %s", answer);

47 of 151

printf("hello, %s", answer);

48 of 151

printf("hello, %s", answer);

49 of 151

printf("hello, %s", answer);

50 of 151

main

51 of 151

int main(void)�{

}

52 of 151

int main(void)�{

}

53 of 151

header files

54 of 151

#include <stdio.h>

int main(void)�{

printf("hello, world");

}

55 of 151

#include <stdio.h>

int main(void)�{

printf("hello, world");

}

56 of 151

#include <stdio.h>

int main(void)�{

printf("hello, world");

}

57 of 151

#include <stdio.h>

int main(void)�{

printf("hello, world\n");

}

58 of 151

help50

59 of 151

style50

60 of 151

check50

61 of 151

cd

cp

ls

mkdir

mv

rm

rmdir

...

62 of 151

types

63 of 151

bool

char

double

float

int

long

string

...

64 of 151

get_char

get_double

get_float

get_int

get_long

get_string

...

65 of 151

format codes

66 of 151

%c

%f

%i

%li

%s

67 of 151

%c char

%f float, double

%i int

%li long

%s string

68 of 151

operators

69 of 151

+

-

*

/

%

70 of 151

+ addition

- subtraction

* multiplication

/ division

% remainder

71 of 151

variables, syntactic sugar

72 of 151

int counter = 0;

73 of 151

int counter = 0;

74 of 151

int counter = 0;

75 of 151

int counter = 0;

76 of 151

counter = counter + 1;

77 of 151

counter = counter + 1;

78 of 151

counter = counter + 1;

79 of 151

counter += 1;

80 of 151

counter++;

81 of 151

conditions

82 of 151

if (x < y)�{

printf("x is less than y\n");

}

83 of 151

if (x < y)�{

printf("x is less than y\n");

}

84 of 151

if (x < y)�{

printf("x is less than y\n");

}

85 of 151

if (x < y)�{

printf("x is less than y\n");

}

else

{� printf("x is not less than y\n");

}

86 of 151

if (x < y)�{

printf("x is less than y\n");

}

else

{� printf("x is not less than y\n");

}

87 of 151

if (x < y)�{

printf("x is less than y\n");

}

else

{� printf("x is not less than y\n");

}

88 of 151

if (x < y)�{

printf("x is less than y\n");

}

else if (x > y)

{� printf("x is greater than y\n");

}

else if (x == y)

{� printf("x is equal to y\n");

}

89 of 151

if (x < y){

printf("x is less than y\n");

}

else if (x > y)

{� printf("x is greater than y\n");

}

else if (x == y)

{� printf("x is equal to y\n");

}

90 of 151

if (x < y)�{

printf("x is less than y\n");

}

else if (x > y)

{� printf("x is greater than y\n");

}

else if (x == y)

{� printf("x is equal to y\n");

}

91 of 151

if (x < y)�{

printf("x is less than y\n");

}

else if (x > y)

{� printf("x is greater than y\n");

}

else

{� printf("x is equal to y\n");

}

92 of 151

loops

93 of 151

while (true)

{

printf("hello, world\n");

}

94 of 151

while (true)

{

printf("hello, world\n");

}

95 of 151

while (true)

{

printf("hello, world\n");

}

96 of 151

while ( )

{

printf("hello, world\n");

}

97 of 151

while (true)

{

printf("hello, world\n");

}

98 of 151

for (int i = 0; i < 50; i = i + 1)

{

printf("hello, world\n");

}

99 of 151

int counter = 0;

while (n > 0)

{

printf("hello, world\n");

i = i + 1;

}

100 of 151

int i = 0;

while (n > 0)

{

printf("hello, world\n");

i = i + 1;

}

101 of 151

int i = 0;

while (n > 0)

{

printf("hello, world\n");

i = i + 1;

}

102 of 151

int i = 0;

while (i < 50)

{

printf("hello, world\n");

i = i + 1;

}

103 of 151

int i = 0;

while (i < 50)

{

printf("hello, world\n");

i = i + 1;

}

104 of 151

int i = 0;

while (i < 50)

{

printf("hello, world\n");

i = i + 1;

}

105 of 151

int i = 0;

while (i < 50)

{

printf("hello, world\n");

i += 1;

}

106 of 151

int i = 0;

while (i < 50)

{

printf("hello, world\n");

i++;

}

107 of 151

int i = 1;

while (i <= 50)

{

printf("hello, world\n");

i++;

}

108 of 151

int i = 50;

while (i > 0)

{

printf("hello, world\n");

i--;

}

109 of 151

for (int i = 0; i < 50; i = i + 1)

{

printf("hello, world\n");

}

110 of 151

for (int i = 0; i < 50; i = i + 1)

{

printf("hello, world\n");

}

111 of 151

for (int i = 0; i < 50; i = i + 1)

{

printf("hello, world\n");

}

112 of 151

for (int i = 0; i < 50; i = i + 1)

{

printf("hello, world\n");

}

113 of 151

for (int counter = 0; i < 50; i )

{

printf("hello, world\n");

}

114 of 151

for (int i = 0; i < 50; i = i + 1)

{

printf("hello, world\n");

}

115 of 151

for (int i = 0; i < 50; i = i + 1)

{

printf("hello, world\n");

}

116 of 151

for (int i = 0; i < 50; i = i + 1)

{

printf("hello, world\n");

}

117 of 151

for (int i = 0; i < 50; i += 1)

{

printf("hello, world\n");

}

118 of 151

for (int i = 0; i < 50; i++)

{

printf("hello, world\n");

}

119 of 151

abstraction

120 of 151

scope

121 of 151

122 of 151

123 of 151

124 of 151

125 of 151

126 of 151

127 of 151

128 of 151

129 of 151

floating-point imprecision

130 of 151

integer overflow

131 of 151

0000

132 of 151

0001

133 of 151

0010

134 of 151

0011

135 of 151

0100

136 of 151

0101

137 of 151

0110

138 of 151

0111

139 of 151

1000

140 of 151

1000

141 of 151

1 January 2000

142 of 151

095

143 of 151

096

144 of 151

097

145 of 151

098

146 of 151

099

147 of 151

100

148 of 151

100

149 of 151

19 January 2038

150 of 151

151 of 151

This is CS50