🌍 CS50x: Introduction to Computer Science · flashcards
CS50x: Introduction to Computer Science Programming in C Flashcards
50 question-and-answer cards covering Programming in C as it is examined in CS50x: Introduction to Computer Science. 24 of them are printed below, taken from across the deck — no signup, no paywall on the preview.
24 sample cards from the Programming in C deck
Sampled from the end of the deck, so these are different cards from the ones shown on the syllabus page.
What is integer overflow?
The error that occurs when a calculation produces a value larger than the highest value the integer type can store; with a fixed number of bits there is no place for the extra carry bit, so the value wraps around (e.g., to a negative or zero value).
What is the maximum value of a signed 32-bit int, and why?
$2^{31} - 1 = 2{,}147{,}483{,}647$. Of the $32$ bits, one is used for the sign, leaving $31$ bits for the magnitude, and one value pattern is used for zero.
Give a real-world consequence of integer overflow.
The Boeing 787 had to be rebooted periodically because an internal counter of hundredths of a second overflowed after about 248 days ($2^{31}$ hundredths of a second), which could cut electrical power. The Y2K problem (storing years as 2 digits) is a related overflow-style error.
What is floating-point imprecision, and why does it happen?
The inability of computers to represent all real numbers exactly, because a float has only a finite number of bits. For example, $\frac{1}{10}$ has no exact binary representation, so 0.1 is stored as something like $0.10000000149\ldots$
How can a programmer reduce floating-point imprecision in C, and can it be eliminated?
Use double (8 bytes) instead of float (4 bytes) to gain more bits of precision. It cannot be fully eliminated — any finite number of bits still cannot represent infinitely many real numbers exactly.
What is the structure of an if / else if / else construct in C, and how many of its branches execute?
if (condition) { ... } else if (condition) { ... } else { ... } — conditions are checked top to bottom and exactly one branch (the first whose condition is true, or the final else) executes.
Why is 'if (x > 0) ... if (x < 0) ... else ...' worse than using else if for a three-way comparison?
Separate if statements are each evaluated unconditionally, wasting comparisons and risking logic errors (the else binds only to the nearest if). Chained if / else if / else evaluates mutually exclusive branches efficiently and correctly.
What does the ternary (conditional) operator ? : do in C?
It is a compact one-line if/else that yields one of two values: condition ? value_if_true : value_if_false. Example: int max = (a > b) ? a : b;
How does a while loop work in C, and how do you write an intentional infinite loop?
while (condition) { body } re-checks the condition before each iteration and repeats the body as long as it is true (possibly zero times). An intentional infinite loop is while (true) { ... }, exited with break or return.
What are the three parts of a C for loop header, e.g., for (int i = 0; i < 3; i++)?
1) Initialization (int i = 0) — runs once at the start; 2) Condition (i < 3) — checked before every iteration, loop runs while true; 3) Update (i++) — runs after each iteration.
How does a do-while loop differ from a while loop, and what is it commonly used for?
A do-while executes its body first and checks the condition after, so the body always runs at least once. It is ideal for validating user input: do { n = get_int(...); } while (n < 1);
What are the three parts of a C function's definition header, as in 'int add(int a, int b)'?
1) The return type (int) — the type of value the function gives back; 2) the function name (add); 3) the parameter list (int a, int b) — the typed inputs (arguments) it accepts.
What is a function prototype in C, and why is one needed?
A declaration of a function's return type, name, and parameters placed before main (ending with a semicolon), e.g., void meow(int n); It is needed because C is read top to bottom — the compiler must know a function exists before it is called, even if it is defined later.
What does the void keyword mean in a C function signature?
As a return type, void means the function returns no value (e.g., void meow(void)). As a parameter list, void means the function takes no arguments.
What is pseudocode and why is it useful?
An informal, human-language description of an algorithm's steps, written before actual code. It helps a programmer plan logic (conditions, loops, functions) without worrying about syntax.
What is a command-line interface (CLI), and how does it differ from a GUI?
A CLI is a text-based way to interact with a computer by typing commands into a terminal, versus a GUI (graphical user interface) with windows, icons, and mouse clicks. Programmers favor the CLI for speed and automation; VS Code includes a built-in terminal for this.
In VS Code as used in CS50, what are the two main areas you work in?
The text editor (top region) where you write source code files like hello.c, and the integrated terminal (bottom region) where you run CLI commands to compile (make) and execute (./hello) programs.
What do the Linux commands ls, cd, and pwd do?
ls lists the files and folders in the current directory; cd changes the current directory (cd .. moves up one level, cd alone returns to the home directory); pwd prints the path of the current working directory.
What do the Linux commands mkdir, cp, mv, and rm do?
mkdir creates a new directory; cp copies a file (cp source dest); mv moves or renames a file; rm removes (deletes) a file — with rm -r it removes a directory and its contents recursively.
What are manual pages (man pages) and how do you use them?
Built-in Unix/Linux documentation for commands and C library functions. Run man followed by the name (e.g., man printf) to see its usage, parameters, and options; CS50 also offers simplified pages at manual.cs50.io.
Name, in order, the four steps of the C compilation pipeline that 'make' hides.
1) Preprocessing — #include and other # directives are expanded (header contents copied in); 2) Compiling — C source is translated to assembly code; 3) Assembling — assembly is translated to machine code (object code); 4) Linking — your object code is combined with the machine code of libraries (e.g., cs50, stdio) into one executable.
In the compilation pipeline, what exactly happens during preprocessing and during linking?
Preprocessing: lines beginning with #, like #include <cs50.h>, are replaced with the actual contents (prototypes) of those header files. Linking: the compiled machine code of your file is merged with the precompiled machine code of the libraries you used, producing the final single executable.
What is an array in C, and how do you declare an array of 3 ints named scores? How are its elements accessed?
An array is a sequence of values of the same type stored back-to-back (contiguously) in memory. Declare it as int scores[3]; Elements are accessed by zero-based index: scores[0], scores[1], scores[2] — C does no bounds checking, so accessing scores[3] is a bug.
How are strings represented in memory in C, and what is stored in argc and argv when main is declared as int main(int argc, string argv[])?
A string is an array of chars terminated by the NUL byte \0, so "HI!" occupies 4 bytes; individual characters are just small numbers ('A' is 65 in ASCII) accessible by index like s[0], and string.h's strlen counts characters up to \0. For command-line arguments, argc (argument count) holds how many words were typed at the prompt and argv (argument vector) is an array of those strings, with argv[0] being the program's own name and argv[1] the first argument; main's return value is the program's exit status — 0 for success, nonzero for error (viewable with echo $?).
What this deck covers
The Programming in C deck follows the CS50x: Introduction to Computer Science Programming in C syllabus — 6 chapters and 21 topics — so questions land on material that is genuinely examinable rather than trivia around it. That works out to roughly 8.3 cards per chapter.
Answers are written to be recallable, not just readable — averaging about 233 characters, which is long enough to carry the reasoning and short enough to say out loud.
A deck like this earns its keep on the second and third pass. Read the syllabus first so you know the shape of the subject, then use the cards to find the specific facts that have not stuck.
Programming in C flashcards FAQ
How many Programming in C flashcards are in this CS50x: Introduction to Computer Science deck?
50 cards. This page previews 24 of them, sampled evenly across the deck so you can judge the difficulty before installing anything.
Are these CS50x: Introduction to Computer Science flashcards free?
Yes. The preview here is free to read with no signup, and the full 50-card deck is free inside the Examius app.
What do the Programming in C cards cover?
They follow the CS50x: Introduction to Computer Science Programming in C syllabus — 6 chapters and 21 topics — so the questions track what is actually examinable.
How should I use these flashcards?
Read the syllabus first so you know the shape of the subject, then drill the deck. Examius schedules each card with spaced repetition, so cards you keep missing come back sooner and ones you know drift further apart.