You are on page 1of 1

Week1 https://docs.cs50.net/2016/fall/notes/1/week1.

html

Scratch vs. C
hello, C
The CS50 Library
Data Types
More C

Now that weve explored some basic programming concepts with Scratch, we can try to use the same
ideas with a more traditional language, C.

Recall that last week, to run our program in Scratch, we would begin with a block that read when
greenflagclicked .

Our example of having Scratch say hello,world can be translated to the following C:

#include <stdio.h>

int main(void)
{
printf("hello,world\n");
}

printf is the equivalent of say in Scratch, and it will print whatever is inside the parentheses.

We notice a bit of syntax, like the double quotes and the semicolon, but we can focus on one
piece at a time.

In Scratch, say was a function that took an argument, or parameter, and the equivalent line in C is:

printf("hello,world\n");

The \n prints a new line, like pressing enter after typing out that message.

And in the case of loops, in Scratch we might have a forever block that does something over and
1 of 24 12/8/2017, 7:49 PM