Introduction to Programming
- 56Unfamiliar
- 0Learning
- 0Familiar
- 0Mastered
- spaceFlip card
- KI knew it
- DI didn't know it
- ←Previous card
- →Next card
What is the primary language that machines ultimately understand?
Binary, which consists of zeros and ones.
Or swipe the card
56 cards
What is the primary language that machines ultimately understand?
Binary, which consists of zeros and ones.
What concept allows programmers to avoid writing code directly in binary?
Abstraction.
What does electricity represent in the context of computer inputs?
Two states: on or off, represented as 1 or 0 (true or false).
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.).
What standard maps numbers to letters, allowing binary to represent text?
ASCII.
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.
What is an algorithm?
A set of step-by-step instructions for solving a problem.
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.
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.
What is pseudocode?
An informal, English-like description of an algorithm, meant to be succinct and convey the point without strict syntax.
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.
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.What is the purpose of the
mainfunction in a C program?It is the starting point of the program's execution, analogous to Scratch's 'when green flag clicked' block.
What C function is used to print formatted output to the console?
printf.What does
\nrepresent in a C string?A newline character, which moves the cursor to the beginning of the next line.
What punctuation typically marks the end of most statements in C?
A semi-colon (
;).How do you declare and initialize an integer variable named
counterwith a value of 0 in C?int counter = 0;What does the
=sign mean in C, particularly incounter = counter + 1;?Assignment: Copy the value on the right into the variable on the left.
What are two more succinct ways to write
counter = counter + 1;in C?counter += 1;orcounter++;.How do you express an 'if' condition in C?
Using the
ifkeyword followed by a boolean expression in parentheses, and curly braces{}for the code block.How do you express an 'if-else' condition in C?
Using
if (condition) { ... } else { ... }.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.When comparing two integers
xandyin C for less than, greater than, or equality, why is anelse if (x == y)condition often unnecessary afterif (x < y)andelse if (x > y)?Because if
xis neither less thanynor greater thany, it must logically be equal toy. The final case can be handled by a simpleelse.How do you create an infinite loop in C using a
whilestatement?while (true) { // code to repeat forever }.How do you create a
forloop 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 }.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.
What C function is used to get a string of input from the user, specifically from the CS50 Library?
get_string.How do you declare a variable of type
stringand assign the result ofget_stringto it in C (using the CS50 Library)?string name = get_string("What is your name?\n");How do you print a variable of type
stringusingprintfin C?You use the format code
%sas a placeholder in the format string, and then pass the string variable as a second argument toprintf. Example:printf("Hello, %s\n", name);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.What is 'source code'?
The human-readable code written by programmers (e.g., in C, Java, Python).
What is 'machine code'?
The binary instructions (zeros and ones) that a computer's CPU directly understands and executes.
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.
What command is used to compile a C program file named
hello.cusing theclangcompiler and create an executable namedhello?clang -o hello hello.cWhat command is used to run an executable file named
helloin a Linux terminal?./helloWhat is the purpose of the
makecommand in CS50 Sandbox?It automates the compilation process, looking for a
.cfile with the same name and runningclangwith appropriate options.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.What C data type is used for numbers that can have decimal points?
floatordouble.How do you print a
floatordoublevariable usingprintfwith a specific number of decimal places (e.g., 2 decimal places)?You use the format code
%.2ffor a float/double, where.2specifies two decimal places. Example:printf("Value: %.2f\n", f);What are the common arithmetic operators in C for addition, subtraction, multiplication, division, and remainder?
+(addition),-(subtraction),*(multiplication),/(division),%(remainder/modulo).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 / 10results in0).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.
Why is
doublegenerally preferred overfloatfor floating-point numbers when precision is important?doubleuses twice as many bits (typically 64 bits vs. 32 bits), providing greater precision and a larger range.How can you determine if an integer
nis even or odd using the remainder operator?If
n % 2 == 0, thennis even; otherwise, it's odd.What does the
||operator mean in C?Logical OR.
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
//.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.
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.
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.
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.
How do you declare a custom function in C that takes an integer
nas input and does not return any value?void cough(int n)followed by curly braces for the function body.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.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.What is a 'do-while' loop in C, and how does it differ from a 'while' loop?
A
do-whileloop executes its code block at least once before checking its condition, whereas awhileloop checks the condition first and might not execute at all.What does the
returnkeyword 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.
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 thestringdata type.

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