Programming Fundamentals Practice Questions: Test Your Knowledge | LearnByTeaching.ai
These 40 programming fundamentals practice questions cover variables and data types, control flow and loops, functions, and arrays and debugging. They range from basic syntax understanding to tracing through code logic, helping you identify gaps before your next coding exam.
40 questions total
Variables, Data Types, and Operators
Covers variable declaration, primitive types, type conversion, and arithmetic/logical operators.
What is the result of the integer division 17 / 5 in most programming languages that distinguish integer and float division?
What does the modulo operator (%) return for 17 % 5?
Which of the following is NOT a valid variable name in most programming languages?
What is the value of x after: x = 5; x += 3; x *= 2;?
What is the boolean result of: (true AND false) OR true?
What is the result of concatenating the string '3' with the string '5' in most languages?
In a statically-typed language, what happens if you try to assign a string to a variable declared as an integer?
What is the difference between == and === in JavaScript?
What is the value of x after: int x = 7; x = x / 2; (assuming x is an integer)?
In languages with short-circuit evaluation, what happens with: false AND someFunction()?
Control Flow and Loops
Covers if/else statements, switch/case, while loops, for loops, and nested control structures.
What is the output of: if (5 > 3) { print('yes') } else { print('no') }?
How many times does this loop execute: for (i = 0; i < 5; i++) { ... }?
What is the output: x = 10; while (x > 0) { x = x - 3; } print(x);?
What does a 'break' statement do inside a loop?
How many times does the inner loop body execute: for (i=0; i<3; i++) { for (j=0; j<4; j++) { ... } }?
What distinguishes a 'while' loop from a 'do-while' loop?
What is the value of sum after: sum = 0; for (i = 1; i <= 5; i++) { if (i % 2 == 0) continue; sum += i; }?
What is the output: for (i = 10; i >= 1; i /= 2) { print(i); }? (assuming integer division)
What is a sentinel value in the context of loops?
What will this print: x = 5; if (x > 3) { if (x > 7) { print('A'); } else { print('B'); } } else { print('C'); }?
Functions and Scope
Covers function definition, parameters, return values, scope rules, and recursion basics.
What is the difference between a parameter and an argument?
What does a function return if it has no explicit return statement (in most languages)?
What is the output: x = 10; function foo() { x = 20; } foo(); print(x);?
What is the output of: function mystery(n) { if (n <= 1) return 1; return n * mystery(n-1); } print(mystery(4));?
What is variable scope?
In pass-by-value, what happens when you pass a variable to a function and modify the parameter inside?
What is a stack overflow in the context of recursion?
What does the following function return: function f(a, b) { return a > b ? a : b; }?
What is the output: function add(a, b=5) { return a + b; } print(add(3));?
What is the output of: function count(n) { if (n > 0) { count(n-1); print(n); } } count(3);?
Arrays, Strings, and Debugging
Covers array operations, string manipulation, common errors, and debugging techniques.
What is the index of the first element in a zero-indexed array?
An array has 10 elements (indices 0-9). What happens if you access index 10?
What is the output: arr = [10, 20, 30, 40]; print(arr[2]);?
What does the following code do: result = ''; for each char in 'hello' { result = char + result; } print(result);?
What is an infinite loop?
What is the difference between a syntax error and a logic error?
Given arr = [3, 1, 4, 1, 5], what is arr.length or len(arr)?
What does this code do: count = 0; for each element in arr { if (element > 0) count++; }?
What is a null pointer (or null reference) exception?
What technique helps find bugs by printing variable values at key points during execution?
Scoring Guide
Total possible: 40
Study Recommendations
- Trace through code by hand on paper before running it — this builds the mental model of how a computer executes instructions
- Write small programs every day to build fluency with syntax and common patterns
- Practice identifying off-by-one errors in loops — check the first and last iterations carefully
- When debugging, isolate the problem by testing small pieces of code independently
- Learn to use your language's debugger with breakpoints rather than relying solely on print statements
More Programming Fundamentals Resources
Want more programming fundamentals practice?
Upload your notes and LearnByTeaching.ai generates unlimited practice questions tailored to your course. Then teach the concepts to AI students who challenge your understanding.
Try LearnByTeaching.ai — It's Free