Stats 01
Stats 01
#include <stdio.h>
int main(void)
{
printf("hello, world");
}
2/3
of CS50 students have never taken CS before
#include <stdio.h>
int main(void)
{
printf("hello, world");
}
● functions
● conditions
● Boolean expressions
● loops
#include <stdio.h>
int main(void)
{
printf("hello, world");
}
int main(void)
{
}
int main(void)
{
}
printf("hello, world");
printf("hello, world");
printf("hello, world");
printf("hello, world");
printf("hello, world");
printf("hello, world");
#include <stdio.h>
int main(void)
{
printf("hello, world");
}
#include <stdio.h>
int main(void)
{
printf("hello, world");
}
#include <stdio.h>
int main(void)
{
printf("hello, world");
}
CS50 Sandbox
sandbox.cs50.io
cd
ls
mkdir
rm
rmdir
...
#include <stdio.h>
int main(void)
{
printf("hello, world");
}
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
...
input → → output
source code →
source code → → machine code
source code → compiler → machine code
#include <stdio.h>
int main(void)
{
printf("hello, world");
}
#include <stdio.h>
int main(void)
{
printf("hello, world\n");
}
clang hello.c
./a.out
clang -o hello hello.c
./hello
string answer = get_string("What's your name?\n");
printf("hello, %s", answer);
string answer = get_string("What's your name?\n");
printf("hello, %s", answer);
string answer = get_string("What's your name?\n");
printf("hello, %s", answer);
string answer = get_string("What's your name?\n");
printf("hello, %s", answer);
string answer = get_string("What's your name?\n");
printf("hello, %s", answer);
string answer = get_string("What's your name?\n");
printf("hello, %s", answer);
string answer = get_string("What's your name?\n");
printf("hello, %s\n", answer);
string answer = get_string("What's your name?\n");
printf("hello, %s\n", answer);
string answer = get_string("What's your name?\n");
printf("hello, %s\n", answer);
clang -o hello hello.c -lcs50
./hello
make hello
./hello
int counter = 0;
int counter = 0;
int counter = 0;
int counter = 0;
counter = counter + 1;
counter = counter + 1;
counter = counter + 1;
counter += 1;
counter++;
if (x < y)
{
printf("x is less than y\n");
}
if (x < y)
{
printf("x is less than y\n");
}
if (x < y)
{
printf("x is less than y\n");
}
if (x < y)
{
printf("x is less than y\n");
}
else
{
printf("x is not less than y\n");
}
if (x < y)
{
printf("x is less than y\n");
}
else
{
printf("x is not less than y\n");
}
if (x < y)
{
printf("x is less than y\n");
}
else
{
printf("x is not less than y\n");
}
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");
}
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");
}
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");
}
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");
}
while (true)
{
printf("hello, world\n");
}
while (true)
{
printf("hello, world\n");
}
while (true)
{
printf("hello, world\n");
}
while ( )
{
printf("hello, world\n");
}
while (true)
{
printf("hello, world\n");
}
for (int i = 0; i < 50; i = i + 1)
{
printf("hello, world\n");
}
int counter = 0;
while (n > 0)
{
printf("hello, world\n");
i = i + 1;
}
int i = 0;
while (n > 0)
{
printf("hello, world\n");
i = i + 1;
}
int i = 0;
while (n > 0)
{
printf("hello, world\n");
i = i + 1;
}
int i = 0;
while (i < 50)
{
printf("hello, world\n");
i = i + 1;
}
int i = 0;
while (i < 50)
{
printf("hello, world\n");
i = i + 1;
}
int i = 0;
while (i < 50)
{
printf("hello, world\n");
i = i + 1;
}
int i = 0;
while (i < 50)
{
printf("hello, world\n");
i += 1;
}
int i = 0;
while (i < 50)
{
printf("hello, world\n");
i++;
}
int i = 50;
while (i > 0)
{
printf("hello, world\n");
i--;
}
for (int i = 0; i < 50; i = i + 1)
{
printf("hello, world\n");
}
for (int i = 0; i < 50; i = i + 1)
{
printf("hello, world\n");
}
for (int i = 0; i < 50; i = i + 1)
{
printf("hello, world\n");
}
for (int i = 0; i < 50; i = i + 1)
{
printf("hello, world\n");
}
for (int counter = 0; i < 50; i )
{
printf("hello, world\n");
}
for (int i = 0; i < 50; i = i + 1)
{
printf("hello, world\n");
}
for (int i = 0; i < 50; i = i + 1)
{
printf("hello, world\n");
}
for (int i = 0; i < 50; i = i + 1)
{
printf("hello, world\n");
}
for (int i = 0; i < 50; i += 1)
{
printf("hello, world\n");
}
for (int i = 0; i < 50; i++)
{
printf("hello, world\n");
}
bool
char
double
float
int
long
string
...
get_char
get_double
get_float
get_int
get_long
get_string
...
%c
%f
%i
%li
%s
%c char
%f float, double
%i int
%li long
%s string
+
%
+ addition
- subtraction
* multiplication
/ division
% remainder
manual pages
CS50 Lab
lab.cs50.io
floating-point imprecision
integer overflow
123
124
125
126
127
128
129
1
120
130
999
1
990
1
900
111
1
110
1
100
1
000
000
integer overflow
1999
1999
1900
This is CS50