Exam Prep 120+ Algorithm and C Python Programming Solved Questions
2026-2027
CS50: Introduction to Computer Science Prep with Detailed Rationales
*Course Code:* CS50
*Course Name:* Introduction to Computer Science
*Topic:* Algorithms, C, and Python Programming
*Academic Year:* 2026/2027
,Question 1
In C programming, which data type should be used to store a single 8-bit character
code under the ASCII standard?
A) int
B) char
C) float
D) double
*CORRECT ANSWER:* B) char
*RATIONALE:* In C, the char data type is specifically designed to store 8-bit single-
byte values, which maps directly to standard ASCII character codes (values ranging
from 0 to 255 or -128 to 127). An int typically occupies 4 bytes (32 bits), while float and
double represent single-precision and double-precision IEEE 754 floating-point numbers
respectively.
---
Question 2
What is the primary function of the compiler (such as `clang` or `gcc`) in the context of
C programming?
A) Executing code line-by-line at runtime
B) Translating source code into low-level machine code object files
C) Automatically fixing logical and structural syntax errors in code
D) Allocating memory dynamically on the heap during execution
*CORRECT ANSWER:* B) Translating source code into low-level machine code
object files
*RATIONALE:* A compiler converts high-level C human-readable source code into
binary machine code (executable instructions composed of 0s and 1s) prior to
execution. Line-by-line execution is the characteristic of an interpreter (e.g., standard
Python). Compilers report syntax errors but cannot fix them automatically, and dynamic
heap allocation occurs at runtime via functions like `malloc()`.
---
Question 3
Consider the following C code snippet:
```c
,int x = 5;
int y = 2;
float result = x / y;
```
What is the exact value stored in result after execution?
A) 2.5
B) 2.0
C) 2
D) 3.0
*CORRECT ANSWER:* B) 2.0
*RATIONALE:* Because both operands `x` and `y` are of type int, C performs
integer division. The fraction is truncated, yielding an integer result of `2`. This integer
is then implicitly promoted to a float when assigned to `result`, yielding `2.0`. To achieve
`2.5`, explicit casting like `(float)x / y` is required.
---
Question 4
Which operator in C is used to determine the memory size in bytes occupied by a
specific variable or type?
A) `sizeof`
B) `length`
C) `memoryof`
D) `countof`
*CORRECT ANSWER:* A) `sizeof`
*RATIONALE:* The `sizeof` operator is a compile-time operator in C that returns the
total storage size, in bytes, required by an expression or typed specifier (e.g.,
`sizeof(int)` returns 4 on most modern 32/64-bit platforms). `length` and `countof` are not
built-in operators in standard C.
---
, Question 5
What is the exact outcome of evaluating the expression `!(5 > 3 && 2 == 4)` in C boolean
logic?
A) 0 (false)
B) 1 (true)
C) Syntax Error
D) Undefined Behavior
*CORRECT ANSWER:* B) 1 (true)
*RATIONALE:* Evaluating inner expressions: `(5 > 3)` is `1` (true). `(2 == 4)` is `0`
(false). The conjunction `1 && 0` evaluates to `0` (false). Applying the logical NOT
operator `!` to `0` yields 1 (true).
---
Question 6
Which condition describes an infinite loop in C construct logic?
A) A loop whose condition evaluation always returns non-zero (true)
B) A loop that executes exactly $N$ times where $N = 2^{31}-1$
C) A loop missing explicit type conversion on its counter
D) A loop using `break` statements inside nested conditionals
*CORRECT ANSWER:* A) A loop whose condition evaluation always returns non-
zero (true)
*RATIONALE:* In C, non-zero values represent true, while zero represents false. If
a loop conditional statement (e.g., `while (1)`) remains permanently non-zero without
internal terminating directives (`break`, `return`), the loop never satisfies its termination
criteria, causing an infinite loop.
---
Question 7
In CS50's `cs50.h` library, which function is used to safely request a single string input
from the user at command-line runtime?
A) `scanf()`
B) `get_string()`