C/C++ MCQs

1. Which of the following is the correct syntax for defining a function in Python?
A) function name() {}
B) def name():
C) func name[] {}
D) define name() {}

Answer: B) def name():

2. In which programming language is System.out.println() used?
A) Python
B) Java
C) C++
D) JavaScript

Answer: B) Java

3. What is the output of print(“Hello” + ” World”) in Python?
A) Hello World
B) HelloWorld
C) Hello + World
D) Hello World

Answer: B) HelloWorld

4. Which of the following is not a valid data type in Python?
A) int
B) string
C) boolean
D) char

Answer: D) char

5. What does the following Python code do? list(range(5))
A) Creates a list of integers from 1 to 5
B) Creates a list of integers from 0 to 4
C) Creates a list of integers from 1 to 4
D) Creates a list of integers from 0 to 5

Answer: B) Creates a list of integers from 0 to 4

6. What is the output of 23 in Python?**
A) 6
B) 8
C) 9
D) 16

Answer: B) 8

7. How do you declare a variable in JavaScript?
A) var name = value;
B) variable name = value;
C) let name := value;
D) define name = value;

Answer: A) var name = value;

8. What is the correct way to comment a single line in C++?
A) # comment
B) /* comment */
C) — comment
D) // comment

Answer: D) // comment

9. In which language is for loop syntax for (int i = 0; i < 10; i++) used?
A) JavaScript
B) Python
C) C++
D) Java

Answer: C) C++

10. What will be the output of print(0.1 + 0.2 == 0.3) in Python?
A) True
B) False
C) None
D) Error

Answer: B) False

11. Which operator is used for string concatenation in JavaScript?
A) &
B) +
C) .
D) *

Answer: B) +

12. What is the purpose of the return statement in a function?
A) To end the function
B) To pass data to the function
C) To send data back from the function
D) To call another function

Answer: C) To send data back from the function

13. How do you create an array in Python?
A) array = []
B) array = {}
C) array = ()
D) array = []

Answer: D) array = []

14. Which of the following is a correct syntax to declare a variable in Python?
A) var name = value
B) let name: value
C) name = value
D) name: value

Answer: C) name = value

15. What is the output of console.log(typeof null) in JavaScript?
A) object
B) null
C) undefined
D) boolean

Answer: A) object

16. Which of the following keywords is used to define a class in Java?
A) class
B) define
C) function
D) struct

Answer: A) class

17. What does the break statement do in a loop?
A) Skips the current iteration
B) Ends the loop
C) Continues to the next iteration
D) Repeats the loop

Answer: B) Ends the loop

18. How do you add a comment in JavaScript?
A) <!– comment –>
B) /* comment */
C) // comment
D) # comment

Answer: C) // comment

19. What will the expression 10 % 3 evaluate to?
A) 3
B) 1
C) 10
D) 0

Answer: B) 1

20. How do you create a dictionary in Python?
A) dict = []
B) dict = {}
C) dict = ()
D) dict = < >

Answer: B) dict = {}

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>