1. Home
  2. Explore
  3. Computer Science
  4. Introduction to Programming

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Content

Introduction to Programming

  • 64Unfamiliar
  • 0Learning
  • 0Familiar
  • 0Mastered
Topic: Machine Language

What is the primary language that machines ultimately understand?

64 questions

  1. 1

    What is the primary language that machines ultimately understand?

    1. A

      Binary, a system of zeros and ones for computers.

    2. B

      C, a powerful text-based programming language.

    3. C

      Decimal, the numerical system familiar to most humans.

    4. D

      Scratch, a high-level visual language for beginners.

    Correct answer
    A

    Binary, a system of zeros and ones for computers.

    Explanation

    The speaker explicitly states that 'This is binary. This is the only language that machines ultimately understand.' Although humans use abstractions, the machine level is binary.

  2. 2

    What does a computer program primarily require in the middle of inputs and outputs?

    1. A

      It needs to do something with the provided inputs.

    2. B

      It demands a CPU with specialized hardware features.

    3. C

      It requires a graphical user interface for interaction.

    4. D

      It needs a compiler to convert binary to source code.

    Correct answer
    A

    It needs to do something with the provided inputs.

    Explanation

    The speaker describes problem-solving as having inputs, wanting outputs, and 'somewhere in the middle, you need to do something with those inputs.'

  3. 3

    What is the fundamental physical resource and its two states that computers rely on?

    1. A

      Electricity, existing as either plugged in or not.

    2. B

      Memory, stored as either volatile or non-volatile states.

    3. C

      Data, existing as either open or closed circuits.

    4. D

      Logic, represented as either true or false conditions.

    Correct answer
    A

    Electricity, existing as either plugged in or not.

    Explanation

    The speaker explains that computers 'only at the end of the day plug into the wall to get their physical resource, electricity, and they might store that temporarily in a battery. But that really is our only input. It's either plugged in or it's not. It's either a 1 or a 0, true or false.'

  4. 4

    What is ASCII used for in the context of computer science?

    1. A

      It is a protocol for efficient data transfer over networks.

    2. B

      It is a global standard for mapping numbers to letters.

    3. C

      It is an abstraction for representing images and videos.

    4. D

      It is a standard for mapping numbers to colors for display.

    Correct answer
    B

    It is a global standard for mapping numbers to letters.

    Explanation

    The speaker explains that ASCII 'is this global standard for mapping numbers to letters' to represent text like 'HI!' from binary values.

  5. 5

    How are colors represented digitally in a program like Photoshop?

    1. A

      By combining different levels of brightness and contrast values.

    2. B

      By interpreting numerical values as amounts of red, green, and blue.

    3. C

      By mapping decimal values directly to color names or codes.

    4. D

      By using specific binary sequences for each predefined color.

    Correct answer
    B

    By interpreting numerical values as amounts of red, green, and blue.

    Explanation

    The speaker explains that values like 72, 73, 33 can be 'interpreted them as like some amount of red, some amount of green, some amount of blue, which gave us last time, recall, this yellowish color.'

  6. 6

    What is the fundamental concept behind animating images or videos on a screen?

    1. A

      Employing complex mathematical algorithms for motion prediction.

    2. B

      Storing full video files as single, compressed digital packets.

    3. C

      Displaying a sequence of images rapidly to the human eye.

    4. D

      Utilizing advanced graphics processing units for real-time rendering.

    Correct answer
    C

    Displaying a sequence of images rapidly to the human eye.

    Explanation

    The speaker states that videos and movies 'are just sequences of images flying past your human eyes really quite quickly.'

  7. 7

    What are algorithms in the context of problem-solving with computers?

    1. A

      They are the secret sauce where problems are actually solved.

    2. B

      They are the graphical interfaces for user interaction.

    3. C

      They are the hardware components that execute instructions.

    4. D

      They are the standardized protocols for input and output.

    Correct answer
    A

    They are the secret sauce where problems are actually solved.

    Explanation

    The speaker refers to algorithms as 'the secret sauce-- this is where the problems are actually solved' within the 'black box' of a program.

  8. 8

    Why is the efficiency of an algorithm represented as a straight line when turning phone book pages one by one?

    1. A

      It indicates a fixed amount of time regardless of book size.

    2. B

      It illustrates the fastest possible method for searching.

    3. C

      It demonstrates that the task is consistently simple and quick.

    4. D

      It shows a direct one-to-one relationship between pages and turns.

    Correct answer
    D

    It shows a direct one-to-one relationship between pages and turns.

    Explanation

    The speaker explains the red line (page-by-page search) is straight 'because there's a one to one correspondence between how many pages there are in the book and how many page turns there are-- one page, one more page, one more turn, and so forth.'

  9. 9

    What was the main issue with the 'two pages at a time' phone book search algorithm?

    1. A

      It significantly increased the overall time required for the search.

    2. B

      It required a more complex logical structure than intended.

    3. C

      It created a risk of missing the target entry between pages.

    4. D

      It made the phone book pages more difficult to turn accurately.

    Correct answer
    C

    It created a risk of missing the target entry between pages.

    Explanation

    The speaker notes the bug was 'I might miss him. He might accidentally get sandwiched in between two pages.'

  10. 10

    What is the primary characteristic of the 'dividing and conquer' algorithm for searching a phone book?

    1. A

      It systematically halves the search space until the target is found.

    2. B

      It requires turning pages exactly two at a time to minimize effort.

    3. C

      It relies on external memory aids to keep track of progress.

    4. D

      It involves rapidly scanning pages from front to back without stopping.

    Correct answer
    A

    It systematically halves the search space until the target is found.

    Explanation

    The speaker describes the dividing and conquer method as 'open it roughly to the middle, look down, and then go left, and go right, and just repeat that process as the problem gets this big to this big to this big to this big to just one page left.'

  11. 11

    What is pseudocode primarily used for in computer science?

    1. A

      To formally define the syntax of a specific programming language.

    2. B

      To express algorithms succinctly and get the point across.

    3. C

      To execute programs directly on a machine without compilation.

    4. D

      To provide detailed, machine-level instructions for a CPU.

    Correct answer
    B

    To express algorithms succinctly and get the point across.

    Explanation

    The speaker defines pseudocode: 'There's no formal definition. It can be English, English like. It's just meant to be succinct and get the point across.'

  12. 12

    What common programming concepts were introduced using pseudocode and demonstrated with Scratch?

    1. A

      Database queries, network protocols, and operating systems.

    2. B

      Graphical user interfaces, event handlers, and threads.

    3. C

      Loops, conditions, Boolean expressions, and variables.

    4. D

      Assembly language, machine code, and memory management.

    Correct answer
    C

    Loops, conditions, Boolean expressions, and variables.

    Explanation

    The speaker lists 'loops and conditions, Boolean expressions, variables, and so forth' as concepts introduced with pseudocode and Scratch.

  13. 13

    What is the main challenge when providing instructions to a computer compared to a human?

    1. A

      Computers require far more precise and explicit details.

    2. B

      Computers struggle to understand natural language metaphors.

    3. C

      Computers cannot execute instructions at variable speeds.

    4. D

      Computers lack the ability to process complex Boolean logic.

    Correct answer
    A

    Computers require far more precise and explicit details.

    Explanation

    The speaker uses the 'open to the middle of the phone book' example to highlight that computers 'need to be precise enough to program the computer correctly' and cannot make the same assumptions as humans.

  14. 14

    What is the benefit of using abstractions in programming, despite potential imprecision?

    1. A

      They provide absolute clarity for every single instruction.

    2. B

      They eliminate the need for any underlying detailed implementation.

    3. C

      They ensure that programs are entirely free of bugs and errors.

    4. D

      They allow for the creation of simpler, shorter programs.

    Correct answer
    D

    They allow for the creation of simpler, shorter programs.

    Explanation

    The speaker notes that abstractions are useful because 'we can then make a 12 step program instead of a 20 step program by elaborating too much.'

  15. 15

    What is the consequence of a computer program lacking specificity or precision?

    1. A

      It will simply perform a different task than intended by the user.

    2. B

      It will automatically adjust itself to fulfill the closest goal.

    3. C

      It will require human intervention to correct errors in real-time.

    4. D

      It will likely crash or produce unexpected, incorrect results.

    Correct answer
    D

    It will likely crash or produce unexpected, incorrect results.

    Explanation

    The speaker warns that 'if you don't handle these corner cases and if you don't think about what that instruction means, you're going to get the proverbial spinning beachball or the hourglass... The program is going to crash, something's going to go wrong.'

  16. 16

    What is the role of building blocks or functions in programming languages like Scratch?

    1. A

      They serve as placeholders for data storage within a program.

    2. B

      They simplify complex tasks by encapsulating detailed operations.

    3. C

      They are fundamental components that cannot be customized or extended.

    4. D

      They are solely used for creating visual effects and animations.

    Correct answer
    B

    They simplify complex tasks by encapsulating detailed operations.

    Explanation

    The speaker refers to making 'own building blocks' and 'own puzzle piece within Scratch' which means 'I never again need to think about or worry about how to implement cough. I can just use that abstraction.'

  17. 17

    What is the primary difference between Scratch and C as programming languages?

    1. A

      Scratch is text-based and powerful, while C is graphical and simpler.

    2. B

      Scratch is graphical and visual, while C is text-based and more powerful.

    3. C

      Scratch focuses on syntax, while C prioritizes conceptual understanding.

    4. D

      Scratch is for complex algorithms, while C is for basic tasks.

    Correct answer
    B

    Scratch is graphical and visual, while C is text-based and more powerful.

    Explanation

    The speaker states, 'today we're going to start to transition from Scratch, this graphical programming language... But we're going to introduce today an older, more traditional language that's just text based. And as such it's a lot more powerful.'

  18. 18

    What is a 'function' in programming terminology?

    1. A

      A loop structure that repeats a block of code indefinitely.

    2. B

      A verb or an action that has specific functionality.

    3. C

      A placeholder for data storage, similar to 'x' in algebra.

    4. D

      A conditional statement that controls program flow.

    Correct answer
    B

    A verb or an action that has specific functionality.

    Explanation

    The speaker identifies the purple block in Scratch as a function, stating 'Yeah, a function. So it was a verb. It was an action, and we're going to call those generally functions. They just have functionality built into them.'

  19. 19

    In C, what is the purpose of printf and how does its F stand for?

    1. A

      printf is for printing files, and F stands for 'file'.

    2. B

      printf is for fast output, and F stands for 'fast'.

    3. C

      printf is for formatted text, and F stands for 'formatted'.

    4. D

      printf is for primary functions, and F stands for 'first'.

    Correct answer
    C

    printf is for formatted text, and F stands for 'formatted'.

    Explanation

    The speaker explains: 'The function, or the verb, is actually not called print. It's called printf, and the F stands for formatted. And it just means that in C you can actually format your text in different ways.'

  20. 20

    What is the significance of \n in a C printf statement?

    1. A

      It represents a special character for bolding text on the screen.

    2. B

      It is an escape character used to literally print a backslash and 'n'.

    3. C

      It instructs the computer to move the cursor to the next line.

    4. D

      It signifies the end of the program and a return to the main menu.

    Correct answer
    C

    It instructs the computer to move the cursor to the next line.

    Explanation

    The speaker clarifies: 'when you want the cursor the text on the screen to move down to the next line, you need to tell the computer that by literally typing backslash n. The human is not going to see a backslash and an n. He or she is actually going to see the cursor move to the next line.'

  21. 21

    What is the equivalent of a period at the end of a sentence in most lines of C code?

    1. A

      A comma (,) separating different parts.

    2. B

      A semicolon (;) at the end of the line.

    3. C

      A colon (:) after the statement.

    4. D

      A period (.) after the last word.

    Correct answer
    B

    A semicolon (;) at the end of the line.

    Explanation

    The speaker states: 'Most lines of code in C have to end in a semi-colon. That's the sort of code equivalent of a period in an English or some other languages sentence.'

  22. 22

    How would you literally display the string \n to a user in C?

    1. A

      Type printf("\ ") in your code.

    2. B

      Type print("\\n") in your code.

    3. C

      Type printf("\\\n") in your code.

    4. D

      Type printf("\n") in your code.

    Correct answer
    B

    Type print("\\n") in your code.

    Explanation

    The speaker explains: 'the way you would show literally to the human a actual backslash n is to actually in your code do backslash backslash n because the second backslash is like saying treat the next character special and actually show it to the human.'

  23. 23

    What is a 'variable' in programming, analogous to 'x' or 'y' in algebra?

    1. A

      A logical condition that evaluates to true or false.

    2. B

      A command that executes a specific action.

    3. C

      A fixed constant that defines program behavior.

    4. D

      A placeholder for data, capable of storing various values.

    Correct answer
    D

    A placeholder for data, capable of storing various values.

    Explanation

    The speaker describes variables as 'like an x and y in algebra. This was just a placeholder for data, and you could store numbers. It turns out you can store words. You can store other things too in other languages.'

  24. 24

    What must you explicitly tell the computer when declaring a variable in C?

    1. A

      The type of data the variable is intended to store.

    2. B

      The exact memory address where the variable will be stored.

    3. C

      The number of times the variable will be accessed.

    4. D

      The maximum value that the variable can hold.

    Correct answer
    A

    The type of data the variable is intended to store.

    Explanation

    The speaker explains, 'You've also got to tell the computer, the type of variable I want is specifically for an integer, otherwise abbreviated int. So you have to tell the computer in advance what type of data you're going to store on it.'

  25. 25

    What does the single equal sign (=) mean in C programming?

    1. A

      It assigns the value on the right to the variable on the left.

    2. B

      It defines a new variable and its data type.

    3. C

      It performs a mathematical operation, such as addition.

    4. D

      It checks for equality between two values.

    Correct answer
    A

    It assigns the value on the right to the variable on the left.

    Explanation

    The speaker clarifies that 'the equal sign in C, like a lot of languages we'll see in the class, actually means assignment. Copy the value on the right into the value on the left.'

  26. 26

    What is plus equals (+=) in C programming?

    1. A

      It is a logical operator for combining conditions.

    2. B

      It is a new data type for storing positive numbers.

    3. C

      It is a shorthand for incrementing a variable by a value.

    4. D

      It is a mathematical operation to subtract a value.

    Correct answer
    C

    It is a shorthand for incrementing a variable by a value.

    Explanation

    The speaker describes plus equals as 'syntactic sugar... It's just a nice fancy feature that lets you write fewer words or characters but do the same thing' as counter = counter + 1.

  27. 27

    What does counter++ achieve in C?

    1. A

      It subtracts one from the counter variable.

    2. B

      It increments the counter variable by one.

    3. C

      It sets counter to its maximum possible value.

    4. D

      It checks if counter is a positive number.

    Correct answer
    B

    It increments the counter variable by one.

    Explanation

    The speaker states that counter++ is a simplification that does the same thing as counter = counter + 1 or counter += 1, all of which increment the variable by one.

  28. 28

    What is a 'condition' in programming?

    1. A

      A function that returns a specific data type.

    2. B

      A variable that stores a true/false value.

    3. C

      A statement that controls program flow based on a Boolean expression.

    4. D

      A block of code that executes repeatedly.

    Correct answer
    C

    A statement that controls program flow based on a Boolean expression.

    Explanation

    The speaker identifies the orange block in Scratch as a condition, stating 'this was a condition. And it had a Boolean expression that we were asking a question of.'

  29. 29

    In C, what is required around the Boolean expression in an if statement?

    1. A

      Curly braces ({})

    2. B

      Square brackets ([])

    3. C

      Angle brackets (<>)

    4. D

      Parentheses (())

    Correct answer
    D

    Parentheses (())

    Explanation

    The speaker explains that for an if statement, 'The only additional thing you need in C is parentheses around the Boolean expression.'

  30. 30

    What do curly braces ({}) represent in C programming?

    1. A

      They act as the C equivalent of Scratch's embracing block shape.

    2. B

      They mark the beginning and end of a function call.

    3. C

      They define the scope of a variable's existence.

    4. D

      They denote the execution of a conditional Boolean expression.

    Correct answer
    A

    They act as the C equivalent of Scratch's embracing block shape.

    Explanation

    The speaker states: 'Curly braces... These are just C's equivalent of this shape. Notice that most of the yellow blocks in Scratch had this embracing or this embracing shape to them. You can simulate that in C by having what's called an open curly brace and then a closed curly brace.'

  31. 31

    Why is the double equal sign (==) used for comparison in C instead of a single equal sign?

    1. A

      To denote a logical 'AND' operation between two conditions.

    2. B

      To signify a more precise comparison of floating-point numbers.

    3. C

      To differentiate it from the assignment operator (=).

    4. D

      To indicate that the comparison is only for Boolean values.

    Correct answer
    C

    To differentiate it from the assignment operator (=).

    Explanation

    The speaker clarifies: 'We already a moment ago decided as humans... equals is actually in the context of C going to be assignment... And so we kind of painted ourselves into a corner. We still as humans, as programmers, want to be able to express the notion of equality and comparing. But if we've already used the equal sign for assignment, we need another pattern of symbols to represent equality. And as it turns out, humans just chose two equal signs instead.'

  32. 32

    How can you optimize an if-else if-else if structure with three possible outcomes?

    1. A

      By adding more conditions to cover all edge cases explicitly.

    2. B

      By nesting all conditions within a single if statement.

    3. C

      By replacing the final else if with a simple else statement.

    4. D

      By converting all conditions into separate switch statements.

    Correct answer
    C

    By replacing the final else if with a simple else statement.

    Explanation

    The speaker suggests: 'I don't need the last condition because, if we all agree logically that either x is less than y or greater than y or maybe equal to y, well, if there's only a third and final case that can just be my so-called else.'

  33. 33

    What is the primary keyword used to create an infinite loop in C, similar to Scratch's 'forever' block?

    1. A

      for with an empty condition.

    2. B

      while with a condition that is always true.

    3. C

      repeat with a large number.

    4. D

      loop with no conditions.

    Correct answer
    B

    while with a condition that is always true.

    Explanation

    The speaker states: 'It turns out c uses the key word while. So there is no forever keyword in C, but there is the word while... You can literally just say true because that key word true never changes value.'

  34. 34

    What is the conventional starting number for counting in C and most programming languages?

    1. A

      Any arbitrary number, depending on the programmer's preference.

    2. B

      1, as it is the natural starting point for humans.

    3. C

      0, reflecting binary's smallest representable value.

    4. D

      Negative 1, to allow for a wider range of values.

    Correct answer
    C

    0, reflecting binary's smallest representable value.

    Explanation

    The speaker explains: 'Almost everyone in this room probably starts counting from 1. Computers just tend to start counting from 0. But why? What's the rationale for starting to count from 0 perhaps based on last week? ...Yeah, it's just ones and zeros, and what's the smallest number... that you can represent in binary? Well, it's just 0.'

  35. 35

    What is a 'string' in the context of programming languages?

    1. A

      A logical condition that evaluates to true or false.

    2. B

      A single character used for display on the screen.

    3. C

      A sequence of characters, such as a word, phrase, or sentence.

    4. D

      A numerical value that represents text data.

    Correct answer
    C

    A sequence of characters, such as a word, phrase, or sentence.

    Explanation

    The speaker defines a string: 'A string in a programming language is just a sequence of characters. It's a word, it's a phrase, it's a character, it's a paragraph. This is a string. Anything between double quotes is a string in C.'

  36. 36

    What is the purpose of percent S (%S) within a printf format string in C?

    1. A

      It serves as a placeholder for a string variable to be plugged in.

    2. B

      It represents a special character for string concatenation.

    3. C

      It is a placeholder for a numerical value to be inserted.

    4. D

      It indicates that the entire output should be treated as a string.

    Correct answer
    A

    It serves as a placeholder for a string variable to be plugged in.

    Explanation

    The speaker explains: 'Percent S is a placeholder, and S stands for string. And that literally is a placeholder saying, printf, I'm going to give you a string to plug in to this first input.'

  37. 37

    What is 'source code' in the context of computer programming?

    1. A

      The graphical representation of a program's logic flow.

    2. B

      The compiled machine code that is ready for execution.

    3. C

      The human-readable code written in languages like C or Java.

    4. D

      The binary code that machines directly understand.

    Correct answer
    C

    The human-readable code written in languages like C or Java.

    Explanation

    The speaker defines source code as 'the English like code we see on the screen that's mildly pleasurable to write as opposed to just zeros and ones.'

  38. 38

    What is the role of a 'compiler' in the programming process?

    1. A

      It converts machine code back into human-readable source code.

    2. B

      It manages the graphical user interface of an operating system.

    3. C

      It executes source code directly without translation.

    4. D

      It converts source code into machine code (zeros and ones).

    Correct answer
    D

    It converts source code into machine code (zeros and ones).

    Explanation

    The speaker explains that humans 'have already written programs that we're going to start calling a compiler that allows us to convert source code to machine code.'

  39. 39

    What is the a.out file generated by a C compiler (like clang) by default?

    1. A

      It is a temporary file used during the compilation process.

    2. B

      It is a log file containing compilation errors and warnings.

    3. C

      It is the original source code file, unchanged.

    4. D

      It is the executable machine code program.

    Correct answer
    D

    It is the executable machine code program.

    Explanation

    The speaker states: 'by convention, they are stored in a file that's weirdly and historically just called a dot out... It stands for assembly output.' This a.out file is the result of the compilation.

  40. 40

    What is a 'terminal window' primarily used for in programming environments?

    1. A

      To design graphical user interfaces and visual elements.

    2. B

      To write and edit source code files with advanced formatting.

    3. C

      To display animated graphics and multimedia content.

    4. D

      To send text-based commands to the computer's operating system.

    Correct answer
    D

    To send text-based commands to the computer's operating system.

    Explanation

    The speaker explains: 'This is an example of a terminal window... you don't bother with these aesthetics. You actually get your hands dirtier with just the keyboard alone typing anything you want to do. And at first, it might feel like a regression... But it's more powerful, and it's more explicit. It lets you do exactly what you want to do by sending commands to the computer.'

  41. 41

    What is the purpose of the make command when compiling a C program?

    1. A

      It automates the compilation process, calling clang with default settings.

    2. B

      It is the actual compiler that converts source code to machine code.

    3. C

      It directly executes the source code without needing a compiler.

    4. D

      It automatically generates a graphical user interface for the program.

    Correct answer
    A

    It automates the compilation process, calling clang with default settings.

    Explanation

    The speaker clarifies: 'Make is not a compiler. Make is not the thing in the middle here converting source code to machine code. It's just a second program that some humans wrote years ago that use clang in an automated way to achieve the same output. Because people got tired of typing stuff like this.'

  42. 42

    What is the significance of the .h file extension (e.g., stdio.h, cs50.h)?

    1. A

      It denotes a file used exclusively for graphical asset storage.

    2. B

      It indicates a file containing executable machine code.

    3. C

      It signifies a file that stores user-defined data and variables.

    4. D

      It stands for 'header' and contains declarations of functions and types.

    Correct answer
    D

    It stands for 'header' and contains declarations of functions and types.

    Explanation

    The speaker explains: 'Technically, CS50 dot h is a header file. Dot h means header, and it's just a file containing C code in which the functions are created.' These files 'teach the computer what printf's inputs are and what printf's output is if any.'

  43. 43

    What is the meaning of the error 'unused variable' in C?

    1. A

      The variable was used before it was properly declared with a type.

    2. B

      The variable was declared but never referenced or used in the code.

    3. C

      The variable was declared but never assigned a value.

    4. D

      The variable's data type is incompatible with its assigned value.

    Correct answer
    B

    The variable was declared but never referenced or used in the code.

    Explanation

    The speaker states: 'Error, unused variable name. That one I kind of understand even without being a programmer. What does that mean? ...Yeah, I'm just kind of wasting the computer's time. I'm creating it... but what's the point of that exercise if you're never... doing anything with it.'

  44. 44

    What is the purpose of int main(void) in a C program?

    1. A

      It serves as the entry point where the program's execution begins.

    2. B

      It defines a custom data type for handling numerical operations.

    3. C

      It is a function that returns the total execution time of the program.

    4. D

      It declares an integer variable named main with no initial value.

    Correct answer
    A

    It serves as the entry point where the program's execution begins.

    Explanation

    The speaker states: 'int main void is perhaps the most cryptic way you can say the equivalent of when green flag clicked. That's all that does... when you're writing a program in C and you want to start the program off, you literally have to type int main void.'

  45. 45

    What is the get_int function from the CS50 library used for?

    1. A

      To display an integer value on the screen with specific formatting.

    2. B

      To obtain an integer value directly from the user's input.

    3. C

      To convert a string input into an integer value.

    4. D

      To calculate the integer part of a floating-point number.

    Correct answer
    B

    To obtain an integer value directly from the user's input.

    Explanation

    The speaker introduces get_int as a function 'if you want to get an integer. So I can actually call get int, and I can say something like integer is the prompt. Like, hey, human, please give me an integer.'

  46. 46

    What is a 'float' data type in computer programming?

    1. A

      A Boolean value representing true or false states.

    2. B

      A real number that can have decimal points and precision.

    3. C

      A character representing a single letter or symbol.

    4. D

      A whole number without any decimal points.

    Correct answer
    B

    A real number that can have decimal points and precision.

    Explanation

    The speaker explains: 'In a computer, those things with decimal points are called floating point values, or floats. And you can think of it as the decimal point can kind of float to the left or the right, depending on how big or small the number is or how precise the numbers after the decimal point are.'

  47. 47

    What does percent f (%f) signify in a printf format string?

    1. A

      It's a placeholder for a character value.

    2. B

      It's a placeholder for a string value.

    3. C

      It's a placeholder for a floating-point value.

    4. D

      It's a placeholder for an integer value.

    Correct answer
    C

    It's a placeholder for a floating-point value.

    Explanation

    The speaker uses %f when printing a float: 'if you use percent i, that says, hey, computer, put an integer here. ...percent f for a float new line comma f semi-colon.'

  48. 48

    What is the result of integer division in C when, for example, 2 is divided by 10?

    1. A

      It will result in 0, truncating the decimal part.

    2. B

      It will result in an error due to invalid operation.

    3. C

      It will result in a floating-point number, 0.2.

    4. D

      It will round up to the nearest whole number, 1.

    Correct answer
    A

    It will result in 0, truncating the decimal part.

    Explanation

    The speaker highlights this behavior: '2 divided by 10 is-- 2 mod y... is 2. So I get four out of five for correctness? What's a little funky here? Yeah, 2 divided by 10? Like, I'm pretty sure that's like 2/10 or maybe one fifth or 0.2. I mean, I'll take any number of answers but not 0. So what's going on? Well, this is a matter of representation. It turns out in a computer program, we decided in advance I'm going to store ints. An int is something that does not have a decimal point.'

  49. 49

    What is the primary reason for imprecision when computers store real numbers (floats/doubles)?

    1. A

      The finite amount of memory prevents representing infinite numbers perfectly.

    2. B

      The display screen cannot render an infinite number of decimal places.

    3. C

      The operating system prioritizes speed over mathematical accuracy.

    4. D

      The computer's clock speed affects the accuracy of calculations.

    Correct answer
    A

    The finite amount of memory prevents representing infinite numbers perfectly.

    Explanation

    The speaker explains: 'If you only have a finite amount of memory, how in the world are we going to represent an infinite number of numbers? ...So at some point, the computer's gotta start cutting some corners.'

  50. 50

    In C, what is a double data type primarily used for compared to a float?

    1. A

      To handle complex numbers with both real and imaginary parts.

    2. B

      To represent integer values with higher magnitude.

    3. C

      To provide twice as many bits for greater precision.

    4. D

      To store negative real numbers more efficiently.

    Correct answer
    C

    To provide twice as many bits for greater precision.

    Explanation

    The speaker states: 'It turns out, if you want twice as many bits, you can literally use a data type called double.' This increases precision.

  51. 51

    When is it generally advisable to avoid comparing floating-point values for exact equality in code?

    1. A

      Only when the numbers are known to be perfectly rational.

    2. B

      Due to potential imprecision in their digital representation.

    3. C

      When performing simple arithmetic operations like addition.

    4. D

      When the values are very small or very large in magnitude.

    Correct answer
    B

    Due to potential imprecision in their digital representation.

    Explanation

    The speaker warns: 'Logically, if I start using equals equals to compare things for equality, it's going to be really hard for me to ever compare something for 2/10 as it's value because I'm going to literally have to remember or write down or figure out this value and compare against that and not just compare more loosely against 0.2. And that's true, you should actually never compare floating point values in code for equality.'

  52. 52

    What is a trade-off when using double for greater precision compared to float?

    1. A

      It uses less processing power but more memory space.

    2. B

      It requires more complex syntax and compilation steps.

    3. C

      It makes the code less readable for other programmers.

    4. D

      It consumes more memory and may impact processing speed.

    Correct answer
    D

    It consumes more memory and may impact processing speed.

    Explanation

    The speaker explains: 'if you use a double, you will avoid this problem a bit more, but what price will you pay, so to speak? Maybe processing power because it's got to deal with more bits at once, and even more literally, more space.'

  53. 53

    How do you determine if a number is even or odd using the modulo operator (%)?

    1. A

      If the number modulo 3 equals 0.

    2. B

      If the number modulo 1 equals 0.

    3. C

      If the number modulo 0 equals 1.

    4. D

      If the number modulo 2 equals 0.

    Correct answer
    D

    If the number modulo 2 equals 0.

    Explanation

    The speaker explains: 'If n, the number user typed in, mod 2, or divided by and then check the remainder of... equals equals 0, you just said it's an even number.'

  54. 54

    What does the double vertical bar (||) operator mean in C?

    1. A

      It signifies a bitwise 'XOR' operation.

    2. B

      It is a logical 'OR' operation.

    3. C

      It represents a logical 'AND' operation.

    4. D

      It performs a comparison for inequality.

    Correct answer
    B

    It is a logical 'OR' operation.

    Explanation

    The speaker states: 'But you might have seen this block similar to this in Scratch. What does the vertical double bar probably imply here? Or, that's it.'

  55. 55

    What is the primary benefit of creating custom functions (like cough) in C?

    1. A

      It allows for better organization and reuse of code.

    2. B

      It guarantees faster execution times compared to direct code.

    3. C

      It hides all underlying complexity from other programmers.

    4. D

      It reduces the total memory footprint of the program.

    Correct answer
    A

    It allows for better organization and reuse of code.

    Explanation

    The speaker discusses abstracting the cough functionality: 'all of the complexity of coughing has been factored out into a function, my own puzzle piece, if you will, that even takes an argument so that now you can literally, if I move this far away and out of mind, now your program is getting pretty interesting because it really just does what it says.' This leads to better organization and reuse.

  56. 56

    Why did the cough() function initially cause an error when called before its definition in cough2.c?

    1. A

      C compilers read code sequentially and need declarations before use.

    2. B

      It attempted to modify a global variable without explicit permission.

    3. C

      The function was missing necessary arguments in its definition.

    4. D

      The function's return type was incorrectly specified as void.

    Correct answer
    A

    C compilers read code sequentially and need declarations before use.

    Explanation

    The speaker explains: 'Because I previously was trying to use cough early on line 7, but I was only teaching the computer what cough was farther down in the file. Frankly C is kind of dumb. It literally reads your code top to bottom left or right. And if you try to do something before you've taught the computer how to do that, you're going to get that kind of undeclared identifier because it just doesn't know what the word is yet.'

  57. 57

    What is a 'function prototype' in C used for?

    1. A

      To execute a function multiple times with varying inputs.

    2. B

      To automatically generate the function's code based on its name.

    3. C

      To provide a hint to the compiler about a function's existence and signature.

    4. D

      To define the entire implementation of a function at the top of the file.

    Correct answer
    C

    To provide a hint to the compiler about a function's existence and signature.

    Explanation

    The speaker states: 'This is what we're going to call the prototype for a function. If you literally just copy the very first line of it that has its name, its inputs if any, and its output if any, that's a prototype semi-colon.' This 'is now enough of a hint to say, hey, computer, this shell exists.'

  58. 58

    What does void mean when used as a function's return type or argument list?

    1. A

      It declares the function as a placeholder for future implementation.

    2. B

      It specifies that the function takes no inputs and/or returns no value.

    3. C

      It signifies that the function operates only on empty or null values.

    4. D

      It indicates that the function will never be executed by the program.

    Correct answer
    B

    It specifies that the function takes no inputs and/or returns no value.

    Explanation

    The speaker explains: 'cough at the moment does not need to take any inputs. So the key word there is void. And we've actually seen that before. Main also has not been taking any inputs. That's why we had the word void... So for today's purposes, this just means that cough neither takes input nor returns a value as output.'

  59. 59

    What is the primary difference between a while loop and a do-while loop in C?

    1. A

      A do-while loop can only contain a single line of code, unlike a while loop.

    2. B

      A while loop is used for counting, while a do-while loop is for conditions.

    3. C

      A do-while loop always executes at least once, while a while loop might not.

    4. D

      A while loop always executes at least once, while a do-while loop might not.

    Correct answer
    C

    A do-while loop always executes at least once, while a while loop might not.

    Explanation

    The speaker notes the do-while loop 'is literally going to do this first and then check the condition and only do it again if the condition is true. So it's a nice way of just flipping things around in terms of order to do something at least once rather than potentially never at all like was the case earlier.'

  60. 60

    What is 'scope' in the context of C variables?

    1. A

      It defines the range of values a variable can store.

    2. B

      It refers to the variable's ability to interact with external files.

    3. C

      It specifies the maximum number of times a variable can be modified.

    4. D

      It indicates the variable's visibility and lifetime within curly braces.

    Correct answer
    D

    It indicates the variable's visibility and lifetime within curly braces.

    Explanation

    The speaker explains: 'in C variables have scope. Scope is a fancy way of saying they only exist in between the curly braces between which they were declared.'

  61. 61

    What is 'integer overflow' in computer programming?

    1. A

      When a number becomes too large for its allocated memory and rolls over.

    2. B

      When an integer value is accessed beyond its defined scope.

    3. C

      When an integer variable is assigned a floating-point value.

    4. D

      When a mathematical operation on integers produces an irrational number.

    Correct answer
    A

    When a number becomes too large for its allocated memory and rolls over.

    Explanation

    The speaker explains integer overflow with the 999 + 1 example: 'If your computer only has space for three digits? Or what if your phone... literally only has room for 3 digits, what is 999 plus 1 if your hardware only has three digits? Well, it's apparently 0. So you get this overflow... The one kind of falls off conceptually, and you roll over to the next value, which is 000.'

  62. 62

    What was the core problem behind the Y2K bug?

    1. A

      Outdated software represented years with only two digits.

    2. B

      A critical hardware component failed when the year changed.

    3. C

      Computers were designed to only operate in the 20th century.

    4. D

      A malicious virus was programmed to activate in the year 2000.

    Correct answer
    A

    Outdated software represented years with only two digits.

    Explanation

    The speaker explains: 'What was the Y2K problem in a nutshell? ...So if they are only using two digits to display values, you could confuse the year 2000 with actually the year 1900 because, long story short, what humans did kind of reasonably decades ago was-- space was expensive... So you know what? If it was like 1970, do we really care about 1969, 1968, let alone 1900? Not really let's just assume we're all in the 1900s and never show or store one 9. Let's just store two digits for every year.'

  63. 63

    What caused the Boeing 787 to lose electrical power after 248 days of continuous operation?

    1. A

      A physical hardware malfunction in its power generators.

    2. B

      An unexpected external interference with its control systems.

    3. C

      An integer overflow in a software counter tracking hundredths of seconds.

    4. D

      A cybersecurity breach that disabled critical aircraft functions.

    Correct answer
    C

    An integer overflow in a software counter tracking hundredths of seconds.

    Explanation

    The speaker cites an article: 'This condition is caused by a software counter internal to the generator that will overflow after 248 days of continuous power. ...they were using 32-bit integers. They were using those integers to store hundredths of seconds. And at some point if you leave your plane on for 248 days... that product of multiplying things out gets big pretty fast. And on day 249, planes theoretically would shut down... because a really big number rolls over to zero and that confused the generator.'

  64. 64

    What is the function of comments (// or /* */) in C code?

    1. A

      They provide human-readable notes and explanations for the code.

    2. B

      They mark sections of code that should be ignored by the linker.

    3. C

      They are executed by the compiler to optimize program performance.

    4. D

      They define special variables that are accessible globally.

    Correct answer
    A

    They provide human-readable notes and explanations for the code.

    Explanation

    The speaker explains: 'A comment is just a note to yourself, to your TF, to your friend, to your colleague, with whoever whom you're writing code with. And it's just a note to self to remind yourself of what the code does.'

Question 1 of 64
Question 1 of 64

Ask anything

We've read this whole study set, so questions about it get the best answers.

FlashcardsQuizFill in the blanksWritten testLessonNotesContent