Online Coding Lessons Practice Test ā Questions and Answers
Question 1: What is the correct way to print 'Hello, World!' in Python?
- System.out.println('Hello, World!')
- print('Hello, World!') (Correct answer)
- console.log('Hello, World!')
- echo 'Hello, World!'
Correct answer: print('Hello, World!')
Python uses the built-in print() function to display output to the console.
Question 2: What is a queue data structure?
- Elements are removed from where they were added
- Elements are sorted automatically
- Elements follow First-In-First-Out (FIFO) order (Correct answer)
- A hierarchical structure
Correct answer: Elements follow First-In-First-Out (FIFO) order
A queue is a data structure that follows the First-In-First-Out (FIFO) principle, like a line of people waiting ā the first in is the first out.
Question 3: What happens when we use a class with parameterized constructors but no default constructor in a program to create an object that requires a zero-argument constructor?
- Runtime error.
- Runtime exception
- Compile-time error. (Correct answer)
- Preprocessing error
Correct answer: Compile-time error.
If a class explicitly defines one or more parameterized constructors but no default (zero-argument) constructor, the compiler will not automatically generate a default constructor. Consequently, attempting to create an object of that class without providing any arguments (e.g., `MyClass obj;`) will result in a compile-time error. The compiler cannot find a matching constructor to instantiate the object.
Question 4: In C, what does a function declared with a 'void' return type indicate?
- It returns an error code
- It returns zero
- It returns no value (Correct answer)
- It returns a pointer
Correct answer: It returns no value
A void return type means the function does not return any value.
Question 5: Which sorting algorithm works by repeatedly swapping adjacent elements if they are in the wrong order?
- Merge Sort
- Bubble Sort (Correct answer)
- Quick Sort
- Insertion Sort
Correct answer: Bubble Sort
Bubble Sort works by repeatedly comparing and swapping adjacent elements until the list is sorted, causing larger values to 'bubble' to the end.
Question 6: What is 'divide and conquer' as a programming strategy?
- Breaking a problem into smaller subproblems, solving them, and combining results (Correct answer)
- Splitting code into multiple files
- A method of sorting by dividing an array in half
- Using two nested loops
Correct answer: Breaking a problem into smaller subproblems, solving them, and combining results
Divide and conquer is an algorithm design strategy that breaks a problem into smaller subproblems, solves each one recursively, and combines the results.
Question 7: In C++, what does passing an argument by reference (using &) avoid compared to passing by value?
- Type checking
- Memory allocation
- Compilation
- Copying the argument (Correct answer)
Correct answer: Copying the argument
Passing by reference avoids making a copy, operating directly on the original object.
Question 8: What is 'pathfinding' in game AI?
- A technique for loading game assets
- The algorithm that determines how NPCs navigate from one point to another (Correct answer)
- A method for drawing paths in a racing game
- Finding and fixing bugs in game code
Correct answer: The algorithm that determines how NPCs navigate from one point to another
Pathfinding algorithms (like A*) are used in game AI to calculate the optimal route for NPCs to travel from one location to another while avoiding obstacles.
Question 9: Which C++ keyword is used to prevent a member function from modifying the object's state?
- const (Correct answer)
- volatile
- mutable
- static
Correct answer: const
Marking a member function const guarantees it will not modify the object's members.
Question 10: What type of JOIN returns only the rows that have matching values in both tables?
- LEFT JOIN
- FULL OUTER JOIN
- INNER JOIN (Correct answer)
- RIGHT JOIN
Correct answer: INNER JOIN
An INNER JOIN returns only the rows where there is a matching value in both tables, excluding rows that have no match.
Question 11: Which keyword creates a variable that can be changed later in JavaScript?
- fixed
- const
- let (Correct answer)
- lock
Correct answer: let
The let keyword makes a variable whose value can be reassigned.
Question 12: What is the purpose of a graph data structure?
- Sorting elements in order
- Storing hierarchical data
- Displaying chart data on a screen
- Representing relationships between objects using nodes and edges (Correct answer)
Correct answer: Representing relationships between objects using nodes and edges
A graph is a data structure that represents relationships between objects using nodes (vertices) connected by edges, modeling networks and connections.
Question 13: What is a 'sprite' in 2D game development?
- A 2D image or animation used to represent characters or objects in a game (Correct answer)
- A type of programming loop
- A background soundtrack
- A collision detection method
Correct answer: A 2D image or animation used to represent characters or objects in a game
In 2D game development, a sprite is a 2D bitmap image or animation used to represent game characters, items, and other visual elements.
Question 14: What does the 'pass' statement do in Python?
- Exits the program
- Skips the current loop iteration
- Passes a value to a function
- Does nothing and acts as a placeholder (Correct answer)
Correct answer: Does nothing and acts as a placeholder
The 'pass' statement is a null operation used as a placeholder where code is syntactically required but no action is needed.
Question 15: What is Pygame?
- A 3D game engine for professionals
- A game design tool for children
- A Python library for creating 2D games and multimedia applications (Correct answer)
- A game development platform for Android
Correct answer: A Python library for creating 2D games and multimedia applications
Pygame is a set of Python modules designed for writing 2D video games, providing tools for graphics, sound, and user input handling.
Question 16: In C, what does the sizeof operator return for an int on most modern 64-bit systems?
- 1 byte
- 8 bytes
- 4 bytes (Correct answer)
- 2 bytes
Correct answer: 4 bytes
An int is typically 4 bytes on most modern platforms regardless of 32- or 64-bit.
Question 17: What does Math.random() give you?
- A letter
- A random number (Correct answer)
- The date
- The biggest number
Correct answer: A random number
Math.random() returns a random decimal number for things like dice.
Question 18: What is the time complexity of a linear search algorithm?
- O(1)
- O(n²)
- O(log n)
- O(n) (Correct answer)
Correct answer: O(n)
Linear search has O(n) time complexity because in the worst case, it must check every element in the list once.
Question 19: What is the correct format specifier to print a floating-point double with printf in C?
- %f (Correct answer)
- %d
- %s
- %c
Correct answer: %f
%f is used to print float and double values with printf.
Question 20: Which operator is used to access a struct member through a pointer in C?
- &
- ::
- -> (Correct answer)
- .
Correct answer: ->
The arrow operator -> dereferences a pointer and accesses the member in one step.
Question 21: What is a 'hitbox' in game development?
- An invisible boundary used to detect collisions around a game object (Correct answer)
- A box that spawns health items
- The area around a boss enemy
- A container for game assets
Correct answer: An invisible boundary used to detect collisions around a game object
A hitbox is an invisible geometric shape placed around a game object to define the area where collisions or interactions can be detected.
Question 22: In C++, which container provides automatic dynamic resizing and contiguous storage?
- std::set
- std::list
- std::map
- std::vector (Correct answer)
Correct answer: std::vector
std::vector stores elements contiguously and grows automatically as needed.
Question 23: In javascript, which operator is used to assign a value to a variable?
- X
- = (Correct answer)
- *
- "
Correct answer: =
The `=` (equals sign) is the assignment operator in JavaScript. Its purpose is to assign the value on its right-hand side to the variable specified on its left-hand side. For instance, `let score = 100;` uses the `=` operator to store the value `100` into the variable `score`.
Question 24: Which data type is used to store a sequence of characters in Python?
- list
- int
- str (Correct answer)
- bool
Correct answer: str
The 'str' (string) data type in Python is used to store sequences of characters.
Question 25: What is the main advantage of binary search over linear search?
- It works on strings only
- It works on unsorted arrays
- It uses less memory
- It is faster, with O(log n) complexity on sorted arrays (Correct answer)
Correct answer: It is faster, with O(log n) complexity on sorted arrays
Binary search has O(log n) time complexity on sorted arrays, making it much faster than linear search's O(n) for large datasets.
Question 26: What does 'NPC' stand for in game development?
- Network Protocol Controller
- Non-Player Character (Correct answer)
- Numeric Processing Code
- New Pixel Component
Correct answer: Non-Player Character
NPC stands for Non-Player Character, referring to characters in a game that are controlled by the computer's AI rather than a human player.
Question 27: Which HTML attribute specifies an alternate text for an image?
- title
- src
- alt (Correct answer)
- caption
Correct answer: alt
The 'alt' attribute provides alternative text for an image when it cannot be displayed, which is important for accessibility.
Question 28: Which SQL command is used to create a new database table?
- BUILD TABLE
- NEW TABLE
- CREATE TABLE (Correct answer)
- MAKE TABLE
Correct answer: CREATE TABLE
CREATE TABLE is the SQL DDL command used to define and create a new table with specified columns and data types.
Question 29: In SQL, what does the wildcard character % represent when used with the LIKE operator?
- Any sequence of zero or more characters (Correct answer)
- Any single digit
- A literal percent sign only
- Exactly one character
Correct answer: Any sequence of zero or more characters
The % wildcard in a LIKE pattern matches any sequence of zero or more characters, making it useful for partial-text searches.
Question 30: What is 'pixel art' commonly used for in game development?
- Debugging visual glitches
- Creating 3D character models
- Testing game performance
- Creating retro-style low-resolution 2D game graphics (Correct answer)
Correct answer: Creating retro-style low-resolution 2D game graphics
Pixel art is a digital art style where images are created at the pixel level, commonly used in indie and retro-style 2D games to create a classic aesthetic.
Question 31: What does the 'static' keyword do for a local variable inside a C function?
- Preserves its value between calls (Correct answer)
- Makes it constant
- Allocates it on the heap
- Makes it global
Correct answer: Preserves its value between calls
A static local variable retains its value across multiple function calls.
Question 32: Which C++ access specifier makes members accessible only within the class itself?
- private (Correct answer)
- protected
- public
- friend
Correct answer: private
private members can only be accessed from within the same class.
Question 33: If an is an integer variable, a=7/3; will yield a result of
- 2.53
- 0
- 2 (Correct answer)
- 3
Correct answer: 2
When performing integer division in many programming languages (like C, C++, or Java), if both operands are integers, the result will also be an integer, and any fractional part is truncated. For `a = 7 / 3;`, the mathematical result is approximately 2.33. Since `a` is an integer variable, the `.33` is discarded, yielding `2`.
Question 34: What is 'collision detection' in game development?
- Detecting network lag
- Determining when two game objects physically overlap or touch (Correct answer)
- Finding bugs in game code
- Detecting game crashes
Correct answer: Determining when two game objects physically overlap or touch
Collision detection is the computational process of determining when two or more game objects intersect or touch, which is crucial for gameplay interactions.
Question 35: What is a 'level editor' in game development?
- A tool for adjusting game difficulty
- A tool for editing game audio
- A software tool that allows designers to visually create and arrange game levels (Correct answer)
- A code debugger for game scripts
Correct answer: A software tool that allows designers to visually create and arrange game levels
A level editor is a visual tool that allows game developers and designers to create, arrange, and test game levels without writing complex code.
Question 36: What is a tree data structure?
- A list of elements in sorted order
- A circular linked list
- A hierarchical structure with a root node and child nodes (Correct answer)
- A hash table with keys
Correct answer: A hierarchical structure with a root node and child nodes
A tree is a non-linear hierarchical data structure with a root node at the top and child nodes branching below it.
Question 37: What is a 'deque' (double-ended queue)?
- A data structure where elements can be added or removed from both ends (Correct answer)
- A sorted stack
- A binary tree structure
- A queue that can only add elements at one end
Correct answer: A data structure where elements can be added or removed from both ends
A deque (double-ended queue) is a data structure that allows insertion and deletion of elements from both the front and the back.
Question 38: What does the length property tell you about an array?
- How many items it has (Correct answer)
- Its name
- Its color
- Its speed
Correct answer: How many items it has
The length property gives the number of items in an array.
Question 39: What is 'delta time' used for in game programming?
- Tracking player score changes
- Measuring the frame rate of a game
- Calculating the time to beat a level
- Making game movement consistent regardless of frame rate (Correct answer)
Correct answer: Making game movement consistent regardless of frame rate
Delta time is the time elapsed since the last frame, used to ensure game movement and physics are consistent regardless of how fast or slow the game runs.
Question 40: What is a dangling pointer in C?
- A pointer set to NULL
- A pointer to a constant
- A pointer to an array
- A pointer to freed or out-of-scope memory (Correct answer)
Correct answer: A pointer to freed or out-of-scope memory
A dangling pointer references memory that has been freed or has gone out of scope.
Question 41: What does 'index' mean in the context of an array?
- The total number of elements
- The position of an element within the array (Correct answer)
- The type of data stored
- The value stored in the array
Correct answer: The position of an element within the array
An index is a numerical position used to access a specific element in an array, typically starting from 0.
Question 42: Which C++ smart pointer ensures exclusive ownership of a resource?
- std::weak_ptr
- std::unique_ptr (Correct answer)
- std::auto_ptr
- std::shared_ptr
Correct answer: std::unique_ptr
std::unique_ptr enforces sole ownership and cannot be copied.
Question 43: Which data structure is best suited for implementing a 'back' button in a browser?
- Queue
- Linked List
- Stack (Correct answer)
- Array
Correct answer: Stack
A stack is ideal for a browser's back button because visited pages are added to the top, and clicking 'back' pops the most recent page off the stack (LIFO).
Question 44: What does the 'game loop' refer to in game programming?
- The core cycle of updating game logic and rendering frames continuously (Correct answer)
- A loop of background music
- An infinite repeating level design
- A circular track in a racing game
Correct answer: The core cycle of updating game logic and rendering frames continuously
The game loop is the central programming pattern that continuously processes input, updates game state, and renders each frame to keep the game running smoothly.
Question 45: What is a linked list?
- An array with a fixed size
- A sorted array
- A tree with two branches
- A data structure where each node points to the next node (Correct answer)
Correct answer: A data structure where each node points to the next node
A linked list is a data structure where each element (node) contains data and a pointer/reference to the next node in the sequence.
Question 46: Which value is a boolean in JavaScript?
- true (Correct answer)
- 42
- [1, 2]
- "hello"
Correct answer: true
A boolean is either true or false.
Question 47: In a binary search tree (BST), where is a new node with a smaller value inserted?
- At the bottom of the tree
- At the root
- To the left of the parent node (Correct answer)
- To the right of the parent node
Correct answer: To the left of the parent node
In a BST, a node with a value smaller than the parent is always inserted to the left of the parent node.
Question 48: What is a hash table?
- A sorted list of numbers
- A data structure that maps keys to values using a hash function (Correct answer)
- A table used in HTML
- A type of binary tree
Correct answer: A data structure that maps keys to values using a hash function
A hash table is a data structure that uses a hash function to map keys to their associated values, allowing for fast lookup operations.
Question 49: What does 'O(1)' mean in Big O notation?
- The algorithm has constant time complexity regardless of input size (Correct answer)
- The algorithm takes no time
- The algorithm takes n steps
- The algorithm uses one byte of memory
Correct answer: The algorithm has constant time complexity regardless of input size
O(1) means constant time complexity ā the algorithm takes the same amount of time regardless of how large the input is.
Question 50: What is a game engine?
- The network server for online games
- The graphics card in a computer
- Software that provides tools and frameworks for building video games (Correct answer)
- The processor inside a gaming console
Correct answer: Software that provides tools and frameworks for building video games
A game engine is a software framework that provides common game development tools ā like rendering, physics, and audio ā so developers don't build everything from scratch.
Question 51: Which of the following is a scripting language commonly used in Roblox game development?
- C#
- JavaScript
- Python
- Lua (Correct answer)
Correct answer: Lua
Roblox uses Luau (a dialect of Lua) as its primary scripting language for creating games and interactive experiences on its platform.
Question 52: Which symbol joins two pieces of text (strings) together?
- *
- + (Correct answer)
- %
- &
Correct answer: +
The plus sign combines strings in a process called concatenation.
Question 53: What is the purpose of the 'Pen' blocks in Scratch?
- To write text in speech bubbles
- To erase the stage
- To change the sprite's color
- To draw lines and shapes on the stage with the sprite (Correct answer)
Correct answer: To draw lines and shapes on the stage with the sprite
The Pen blocks in Scratch allow sprites to draw lines and shapes on the stage as they move, creating visual patterns or art.
Question 54: Which loop is used to iterate over a sequence in Python?
- for loop (Correct answer)
- do-while loop
- repeat loop
- while loop
Correct answer: for loop
The 'for' loop in Python is used to iterate over sequences like lists, strings, or ranges.
Question 55: What does 'procedural generation' mean in game design?
- Algorithmically creating content (levels, terrain) at runtime rather than manually designing it (Correct answer)
- Writing procedural code in C++
- A testing methodology for games
- Following step-by-step development procedures
Correct answer: Algorithmically creating content (levels, terrain) at runtime rather than manually designing it
Procedural generation is a technique that uses algorithms to automatically create game content ā like levels, worlds, or items ā often resulting in unique experiences each playthrough.
Question 56: What does 'open world' mean in game design?
- A multiplayer online game
- A game with no storyline
- A game with an online leaderboard
- A game design where players can freely explore a large environment without linear restrictions (Correct answer)
Correct answer: A game design where players can freely explore a large environment without linear restrictions
An open world game design gives players the freedom to explore a large virtual environment and complete objectives in any order, rather than following a strictly linear path.
Question 57: What is a stack data structure?
- A structure where elements are added and removed from the front
- A structure where elements follow Last-In-First-Out (LIFO) order (Correct answer)
- A collection of key-value pairs
- A sorted list of elements
Correct answer: A structure where elements follow Last-In-First-Out (LIFO) order
A stack is a linear data structure that follows the Last-In-First-Out (LIFO) principle, where the last element added is the first to be removed.
Question 58: Cout is an object.
- False
- True (Correct answer)
Correct answer: True
In C++, `cout` is indeed an object, specifically an object of the `ostream` class. It is part of the `iostream` library and is used for sending data to the standard output device, typically the console. As an object, `cout` has various member functions and properties that facilitate formatted output.
Question 59: What is the result of the C expression 7 / 2 when both operands are integers?
- 3 (Correct answer)
- 3.0
- 3.5
- 4
Correct answer: 3
Integer division in C truncates the fractional part, yielding 3.
Question 60: Which popular game engine uses C# as its primary scripting language?
- Godot
- Unreal Engine
- Unity (Correct answer)
- GameMaker
Correct answer: Unity
Unity primarily uses C# as its scripting language, making it one of the most widely used game engines for 2D and 3D games.
Online Coding Lessons Practice Test
Assesses foundational and applied coding skills across programming fundamentals, data structures and algorithms, game development, and mobile app development using languages such as C, C++, Python, and JavaScript.
Exam Rules
- You can skip questions and return to them later
- Flag questions for review before submitting
- No feedback shown until you submit the entire exam
- Unanswered questions count as wrong ā answer everything
- 10 pretest questions are mixed in and don't affect your score
- Timer auto-submits when time runs out
- Your progress is auto-saved every 30 seconds