Introduction to C, C++, Java & Python MCQs with Answers
Which of the following is the correct way to declare a variable in C?
a) int 10x;
b) int x = 10;
c) int x:10;
d) int x == 10;
In C++, what is the correct syntax for a for loop?
a) for (int i = 0; i < 10; i++)
b) for (i = 0; i < 10; ++i)
c) for (i < 10; i++)
d) for int i = 0 to 10
In Java, which keyword is used to define a class?
a) function
b) class
c) struct
d) object
Which of the following is a valid Python variable name?
a) 2variable
b) _variable
c) variable-name
d) class
In C++, which operator is used for memory allocation?
a) malloc()
b) calloc()
c) new
d) alloc()
Which of the following data types does Python not support?
a) int
b) float
c) char
d) complex
In C, which header file is required to use the printf() function?
a) #include <stdio.h>
b) #include <stdlib.h>
c) #include <iostream>
d) #include <string.h>
Which of the following is used to declare a constant in Java?
a) final
b) constant
c) static
d) immutable
In Python, which of the following is used to define a function?
a) def
b) function
c) fun
d) create
In C++, what is the keyword used to derive a class from a base class?
a) inherit
b) extends
c) implements
d) :
Which of the following is a feature of Java?
a) Platform-dependent
b) Platform-independent
c) Machine-dependent
d) Uses low-level programming
Which of the following Python data types is immutable?
a) list
b) tuple
c) dict
d) set
What is the default value of a boolean variable in Java?
a) 1
b) false
c) true
d) 0
In C, which of the following is the correct way to define an array?
a) int arr[5];
b) int arr(5);
c) int arr = {5};
d) int[5] arr;
In Python, what does the len() function return?
a) Length of a string
b) Number of items in a list
c) Size of an integer
d) All of the above
Which of the following is the correct way to declare a class in Python?
a) class MyClass {}
b) class MyClass:
c) MyClass class:
d) class MyClass[]
What will be the output of the following Java code?
System.out.println(2 + 3 * 4);
a) 14
b) 20
c) 11
d) 10
Which of the following is used to implement a method in Java?
a) def
b) public
c) void
d) function
What does the == operator do in C?
a) Compares two values
b) Assigns a value to a variable
c) Initializes a variable
d) None of the above
In Java, which of the following is the correct syntax for a switch statement?
a) switch (x) {case 1: break;}
b) switch x {case 1:}
c) switch (x) {if 1: break;}
d) switch [x] {1: break;}
In Python, how do you handle exceptions?
a) catch
b) try-catch
c) try-except
d) handle
In C++, what is used to output data to the console?
a) printf()
b) cout
c) echo
d) print()
Which of the following statements is true about Python?
a) Python is a compiled language
b) Python is a strongly typed language
c) Python is a low-level language
d) Python is not object-oriented
Which of the following is NOT a keyword in Java?
a) extends
b) super
c) dynamic
d) final
In C, what does the scanf() function do?
a) Accepts input from the user
b) Prints output to the console
c) Returns the size of the variable
d) Initializes a variable
In Python, how can you define a list?
a) list = (1, 2, 3)
b) list = [1, 2, 3]
c) list = {1, 2, 3}
d) list = <1, 2, 3>
Which of the following Java operators is used for concatenation?
a) +
b) –
c) *
d) &
Which of the following is the correct method to read user input in Java?
a) cin.next()
b) input()
c) System.in.read()
d) Scanner.nextLine()
Which of the following is NOT a valid C++ loop structure?
a) for
b) while
c) foreach
d) do-while
Which of the following is the correct way to output “Hello World” in Python?
a) echo(“Hello World”)
b) printf(“Hello World”)
c) print(“Hello World”)
d) cout << “Hello World”
In Java, how is a constructor declared?
a) void ConstructorName()
b) ConstructorName()
c) class ConstructorName()
d) public ConstructorName()