MCQ Practice Hub

Programming MCQs

Q1. What is the correct way to declare a variable in Python?

Show Answer

Correct: x = 5

Python uses dynamic typing and doesn't require type declarations or keywords like 'var'. You simply assign a value to a variable name.

Q2. Which of the following is NOT a primitive data type in JavaScript?

Show Answer

Correct: Array

Array is an object type in JavaScript, not a primitive. The primitive types include String, Number, Boolean, Undefined, Null, Symbol, and BigInt.

Q3. What does the acronym 'HTML' stand for?

Show Answer

Correct: Hyper Text Markup Language

HTML stands for Hyper Text Markup Language. It is the standard markup language for creating web pages.

Q4. In most programming languages, what is the index of the first element in an array?

Show Answer

Correct: 0

Most programming languages use zero-based indexing, meaning the first element is at index 0. This includes languages like C, Java, Python, and JavaScript.

Q5. What will be the output of: print(10 / 3) in Python 3?

Show Answer

Correct: 3.3333333333333335

In Python 3, the / operator performs floating-point division and returns a float with full precision, which results in 3.3333333333333335.

Q6. Which loop is guaranteed to execute at least once?

Show Answer

Correct: do-while loop

A do-while loop checks its condition after executing the loop body, ensuring it runs at least once. Other loops check the condition first.

Q7. What is the purpose of the 'break' statement in programming?

Show Answer

Correct: To exit a loop or switch statement prematurely

The 'break' statement is used to immediately exit from a loop (for, while, do-while) or a switch statement, regardless of the loop condition.

Q8. Which of these is the correct way to write a single-line comment in Java?

Show Answer

Correct: // This is a comment

In Java, single-line comments start with //. Multi-line comments use /* */. HTML uses <!-- -->, and Python uses #.

Q9. What does 'CSS' stand for in web development?

Show Answer

Correct: Cascading Style Sheets

CSS stands for Cascading Style Sheets. It is used to style and layout web pages, including colors, fonts, and spacing.

Q10. In object-oriented programming, what is encapsulation?

Show Answer

Correct: Bundling data and methods that operate on that data within a single unit

Encapsulation is the principle of bundling data (attributes) and methods (functions) that operate on the data into a single unit (class), while hiding internal implementation details.

Next ➡

Page 1 of 3