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

  • 56Unfamiliar
  • 0Learning
  • 0Familiar
  • 0Mastered
Topic: Fundamentals of Computing
  • spaceFlip card
  • KI knew it
  • DI didn't know it
  • ←Previous card
  • →Next card

What is the primary language that machines ultimately understand?

Tap to flipClick to flipspace

Binary, which consists of zeros and ones.

Or swipe the card

56 cards

  1. What is the primary language that machines ultimately understand?

    Binary, which consists of zeros and ones.

  2. What concept allows programmers to avoid writing code directly in binary?

    Abstraction.

  3. What does electricity represent in the context of computer inputs?

    Two states: on or off, represented as 1 or 0 (true or false).

  4. How can multiple binary digits (bits) represent more than just 0 or 1?

    By permuting them, allowing for a wider range of numbers (e.g., 0, 1, 2, 3, etc.).

  5. What standard maps numbers to letters, allowing binary to represent text?

    ASCII.

  6. How can the same numerical values (e.g., 72, 73, 33) be interpreted as different types of data, such as colors?

    Through different abstractions; for colors, they might represent amounts of red, green, and blue.

  7. What is an algorithm?

    A set of step-by-step instructions for solving a problem.

  8. Explain the efficiency of a 'linear search' algorithm, like turning phone book pages one by one.

    It has a one-to-one correspondence between the number of pages and the number of page turns, making it a 'straight line' on a graph of time vs. input size.

  9. What is the 'divide and conquer' algorithm for searching a phone book?

    Opening it roughly to the middle, deciding if the target is left or right, and repeating the process on the smaller section until the target is found.

  10. What is pseudocode?

    An informal, English-like description of an algorithm, meant to be succinct and convey the point without strict syntax.

  11. Why is it important to be precise when giving instructions to a computer, even if humans understand vague terms like 'open to the middle of the phone book'?

    Computers (or 'newbies'/robots) lack intuitive understanding and require explicit, unambiguous instructions to avoid errors or unexpected behavior.

  12. What is the purpose of the #include <stdio.h> line in a C program?

    It includes the standard input/output library, which provides functions like printf.

  13. What is the purpose of the main function in a C program?

    It is the starting point of the program's execution, analogous to Scratch's 'when green flag clicked' block.

  14. What C function is used to print formatted output to the console?

    printf.

  15. What does \n represent in a C string?

    A newline character, which moves the cursor to the beginning of the next line.

  16. What punctuation typically marks the end of most statements in C?

    A semi-colon (;).

  17. How do you declare and initialize an integer variable named counter with a value of 0 in C?

    int counter = 0;

  18. What does the = sign mean in C, particularly in counter = counter + 1;?

    Assignment: Copy the value on the right into the variable on the left.

  19. What are two more succinct ways to write counter = counter + 1; in C?

    counter += 1; or counter++;.

  20. How do you express an 'if' condition in C?

    Using the if keyword followed by a boolean expression in parentheses, and curly braces {} for the code block.

  21. How do you express an 'if-else' condition in C?

    Using if (condition) { ... } else { ... }.

  22. Why does C use == for comparison of equality instead of a single =?

    Because a single = is used for assignment, so == is needed to distinguish between assigning a value and checking if two values are equal.

  23. When comparing two integers x and y in C for less than, greater than, or equality, why is an else if (x == y) condition often unnecessary after if (x < y) and else if (x > y)?

    Because if x is neither less than y nor greater than y, it must logically be equal to y. The final case can be handled by a simple else.

  24. How do you create an infinite loop in C using a while statement?

    while (true) { // code to repeat forever }.

  25. How do you create a for loop in C that repeats an action a specific number of times (e.g., 50 times)?

    for (int i = 0; i < 50; i++) { // code to repeat 50 times }.

  26. Why do computers often start counting from 0 instead of 1?

    It aligns with binary representation, where 0 is the smallest value, efficiently utilizing all possible permutations of bits.

  27. What C function is used to get a string of input from the user, specifically from the CS50 Library?

    get_string.

  28. How do you declare a variable of type string and assign the result of get_string to it in C (using the CS50 Library)?

    string name = get_string("What is your name?\n");

  29. How do you print a variable of type string using printf in C?

    You use the format code %s as a placeholder in the format string, and then pass the string variable as a second argument to printf. Example: printf("Hello, %s\n", name);

  30. What is 'concatenation' and how is it achieved when printing in C using printf?

    Concatenation is combining two or more strings end-to-end. In printf, it's achieved by putting literal text and format codes together in the format string, then providing the corresponding variables.

  31. What is 'source code'?

    The human-readable code written by programmers (e.g., in C, Java, Python).

  32. What is 'machine code'?

    The binary instructions (zeros and ones) that a computer's CPU directly understands and executes.

  33. What is a 'compiler' and what is its role in programming?

    A program that translates source code (human-readable code) into machine code (binary instructions) that a computer can execute.

  34. What command is used to compile a C program file named hello.c using the clang compiler and create an executable named hello?

    clang -o hello hello.c

  35. What command is used to run an executable file named hello in a Linux terminal?

    ./hello

  36. What is the purpose of the make command in CS50 Sandbox?

    It automates the compilation process, looking for a .c file with the same name and running clang with appropriate options.

  37. What does int i = get_int("Integer: "); do in C (using CS50 Library)?

    It prompts the user to enter an integer, reads the input, and stores it in an integer variable named i.

  38. What C data type is used for numbers that can have decimal points?

    float or double.

  39. How do you print a float or double variable using printf with a specific number of decimal places (e.g., 2 decimal places)?

    You use the format code %.2f for a float/double, where .2 specifies two decimal places. Example: printf("Value: %.2f\n", f);

  40. What are the common arithmetic operators in C for addition, subtraction, multiplication, division, and remainder?

    + (addition), - (subtraction), * (multiplication), / (division), % (remainder/modulo).

  41. What happens when you divide two integers in C (e.g., 2 / 10)?

    Integer division occurs, meaning the result will be an integer, truncating any decimal part (e.g., 2 / 10 results in 0).

  42. Why is it impossible for computers to precisely represent all real numbers?

    Because computers have a finite amount of memory (bits) to store numbers, while there is an infinite number of real numbers, especially those with non-terminating decimal expansions.

  43. Why is double generally preferred over float for floating-point numbers when precision is important?

    double uses twice as many bits (typically 64 bits vs. 32 bits), providing greater precision and a larger range.

  44. How can you determine if an integer n is even or odd using the remainder operator?

    If n % 2 == 0, then n is even; otherwise, it's odd.

  45. What does the || operator mean in C?

    Logical OR.

  46. What is a 'comment' in C and how is a single-line comment written?

    A note in the code for human readers that the compiler ignores. A single-line comment starts with //.

  47. What is the problem known as 'integer overflow'?

    When an arithmetic operation attempts to create a numeric value that is too large to be stored within the available memory (number of bits) for that data type, causing the value to 'roll over' to a different (often negative or zero) value.

  48. Provide a real-world example of an integer overflow bug.

    The Boeing 787 grounding, where a software counter for hundredths of seconds overflowed after 248 days of continuous operation, causing generators to go into fail-safe mode.

  49. What is 'integer underflow'?

    When an arithmetic operation attempts to create a numeric value that is too small to be stored within the available memory for that data type, causing the value to 'roll over' to a different (often very large positive) value.

  50. Provide a real-world example of an integer underflow bug in a game.

    In the game Civilization, Gandhi's aggression level (stored as a single byte) would underflow from 1 to 255 if he adopted democracy, making him extremely aggressive.

  51. How do you declare a custom function in C that takes an integer n as input and does not return any value?

    void cough(int n) followed by curly braces for the function body.

  52. Why is it important to provide a 'prototype' for a custom function at the top of a C file, even if the full function definition appears later?

    Because the C compiler reads code from top to bottom. A prototype (e.g., void cough(int n);) informs the compiler about the function's existence, inputs, and output before it's actually called or fully defined.

  53. What is the 'scope' of a variable in C?

    The region of the code where a variable is accessible, typically between the curly braces ({}) where it was declared.

  54. What is a 'do-while' loop in C, and how does it differ from a 'while' loop?

    A do-while loop executes its code block at least once before checking its condition, whereas a while loop checks the condition first and might not execute at all.

  55. What does the return keyword do in a C function?

    It specifies the value that the function will send back to the calling code and also terminates the function's execution.

  56. What is the purpose of the #include <cs50.h> line in a C program?

    It includes the CS50 custom library, providing functions like get_string, get_int, get_float, and the string data type.

Card 1 of 56
Card 1 of 56

Ask anything

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

FlashcardsQuizFill in the blanksWritten testLessonNotesContent