Part 2! [https://www.youtube.com/watch?v=ix5jPkxsr7M&list=PLWKjhJtqVAbmGw5fN5BQlwuug-8bDmabi&index=2]
18:51 Scratch code Translated C code (to say something)
- parentheses () represent the bubble in Scratch
- printf to print words, f meaning formatted
- print words must be in double quotations ""
- to move print to the next line ala Microsoft Word, you have to type "/n"
- Most lines in C have to end with a semicolon ;
- Scratch bubbles () in C are curly brackets {}
21:15 Scratch code Translated C code, the counter
- set counter to 0 --> int counter = 0;, int meaning integer, the type of variable
21:54 Change counter by 1
- counter = counter + 1 (Copy the value on the right to the value on the left)
- or, counter += 1;, counter++;
25:53 Whitespace
- whitespace does not matter to the computer
29:06 == to represent Equal
- = to represent assignment, == represents equality
32:33 Scratch code Loop Translated to C
- forever say hello world --> while { printf ("hello world/n") }
- while wants you to ask a question every time it loops
- if the answer is yes, it is going to run the loop
- so change while to while (true) to create a loop
36:22 Repeat 50 in Scratch Translated to C
- repeat = for ("For now")
- Use a variable so for will only repeat 50 times
37:30
- for (int i = 0;)
- what this means: create a variable named i, store integers in i, and set initial value to 0
37:57 Why computers count from 0
- Aside from negative values, 0 is the lowest number in binary
38:48
- for (int i = 0; i <50; i++)
- what this does: set i to 0 and prepare to store integers in it, check the condition just in case the value is larger than initialized
- after executing the lines of code, i++ means i will increment by 1 meaning i = 1 and so on
- Note: it will stop at 50 because 51 would be < 50
40:48 Scratch input to C
- Scratch
- Ask (What's your name?) and wait
- C
- new function called get_string
- underscore is convention in C, you can't use spaces in names of functions
- get_string("What's your name?/n")
- A string in a programming language is a sequence of characters
- anything between the double quotes is a stringin C
- ✔ n means end of line, as before
42:21 Answer variable for the Return Value
- answer = get_string("What's your name?/n")
- To be more precise, string answer = get_string("What's your name?/n")
- What this means: give me a string, call it answer, and assign what is to the right
- What is to the right is whatever get_string comes back with, and is stored from right to left
43:13 Saying the Answer (Person's Name)
- printf ("%s", answer);
- what this means: printf is being told to print out a string that looks like " "
- percent S is a placeholder, with S meaning string
- So the placeholder is telling printf that it is going to give a string to plug in to the first input
- That string being the variable answer
45:03 Asking and saying, Hello, Name
- string answer = get_string("What's your name?/n");
- printf("hello, %s", answer);
49:50 CS50 Sandbox
52:06 Converting Source Code (like C, codes humans have written) to Machine Code (like binary, code "hardwired from the factory")
- 53:07 Other humans have written programs called a compiler that turns source code into machine code
54:03 $ Prompt
- A dollar sign is typically used represent a prompt
- Terminal window sends commands to the computer