🎓LearnByTeaching.aiTry Free
Practice Questions

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.

Q1Easyvariables-and-data-types

What is the result of the integer division 17 / 5 in most programming languages that distinguish integer and float division?

Q2Easyvariables-and-data-types

What does the modulo operator (%) return for 17 % 5?

Q3Easyvariables-and-data-types

Which of the following is NOT a valid variable name in most programming languages?

Q4Easyvariables-and-data-types

What is the value of x after: x = 5; x += 3; x *= 2;?

Q5Mediumvariables-and-data-types

What is the boolean result of: (true AND false) OR true?

Q6Mediumvariables-and-data-types

What is the result of concatenating the string '3' with the string '5' in most languages?

Q7Mediumvariables-and-data-types

In a statically-typed language, what happens if you try to assign a string to a variable declared as an integer?

Q8Mediumvariables-and-data-types

What is the difference between == and === in JavaScript?

Q9Hardvariables-and-data-types

What is the value of x after: int x = 7; x = x / 2; (assuming x is an integer)?

Q10Hardvariables-and-data-types

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.

Q11Easycontrol-flow

What is the output of: if (5 > 3) { print('yes') } else { print('no') }?

Q12Easyloops

How many times does this loop execute: for (i = 0; i < 5; i++) { ... }?

Q13Mediumloops

What is the output: x = 10; while (x > 0) { x = x - 3; } print(x);?

Q14Easyloops

What does a 'break' statement do inside a loop?

Q15Mediumloops

How many times does the inner loop body execute: for (i=0; i<3; i++) { for (j=0; j<4; j++) { ... } }?

Q16Mediumloops

What distinguishes a 'while' loop from a 'do-while' loop?

Q17Mediumloops

What is the value of sum after: sum = 0; for (i = 1; i <= 5; i++) { if (i % 2 == 0) continue; sum += i; }?

Q18Hardloops

What is the output: for (i = 10; i >= 1; i /= 2) { print(i); }? (assuming integer division)

Q19Mediumloops

What is a sentinel value in the context of loops?

Q20Hardcontrol-flow

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.

Q21Easyfunctions

What is the difference between a parameter and an argument?

Q22Easyfunctions

What does a function return if it has no explicit return statement (in most languages)?

Q23Mediumfunctions

What is the output: x = 10; function foo() { x = 20; } foo(); print(x);?

Q24Mediumfunctions

What is the output of: function mystery(n) { if (n <= 1) return 1; return n * mystery(n-1); } print(mystery(4));?

Q25Easyfunctions

What is variable scope?

Q26Mediumfunctions

In pass-by-value, what happens when you pass a variable to a function and modify the parameter inside?

Q27Mediumfunctions

What is a stack overflow in the context of recursion?

Q28Mediumfunctions

What does the following function return: function f(a, b) { return a > b ? a : b; }?

Q29Hardfunctions

What is the output: function add(a, b=5) { return a + b; } print(add(3));?

Q30Hardfunctions

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.

Q31Easyarrays-and-lists

What is the index of the first element in a zero-indexed array?

Q32Easyarrays-and-lists

An array has 10 elements (indices 0-9). What happens if you access index 10?

Q33Easyarrays-and-lists

What is the output: arr = [10, 20, 30, 40]; print(arr[2]);?

Q34Mediumstring-manipulation

What does the following code do: result = ''; for each char in 'hello' { result = char + result; } print(result);?

Q35Easydebugging-techniques

What is an infinite loop?

Q36Mediumdebugging-techniques

What is the difference between a syntax error and a logic error?

Q37Easyarrays-and-lists

Given arr = [3, 1, 4, 1, 5], what is arr.length or len(arr)?

Q38Mediumarrays-and-lists

What does this code do: count = 0; for each element in arr { if (element > 0) count++; }?

Q39Harddebugging-techniques

What is a null pointer (or null reference) exception?

Q40Harddebugging-techniques

What technique helps find bugs by printing variable values at key points during execution?

Scoring Guide

Total possible: 40

Excellent36-40: Excellent — you have strong mastery of programming fundamentals
Good28-35: Good — solid foundation with some gaps to address
Needs WorkBelow 28: Needs work — review the topics where you struggled

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
0 of 40 answered0%

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