Computer

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;

Answer
b) 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

Answer
a) for (int i = 0; i < 10; i++)

In Java, which keyword is used to define a class?
a) function
b) class
c) struct
d) object

Answer
b) class

Which of the following is a valid Python variable name?
a) 2variable
b) _variable
c) variable-name
d) class

Answer
b) _variable

In C++, which operator is used for memory allocation?
a) malloc()
b) calloc()
c) new
d) alloc()

Answer
c) new

Which of the following data types does Python not support?
a) int
b) float
c) char
d) complex

Answer
c) char

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>

Answer
a) #include <stdio.h>

Which of the following is used to declare a constant in Java?
a) final
b) constant
c) static
d) immutable

Answer
a) final

In Python, which of the following is used to define a function?
a) def
b) function
c) fun
d) create

Answer
a) def

In C++, what is the keyword used to derive a class from a base class?
a) inherit
b) extends
c) implements
d) :

Answer
d) :

Which of the following is a feature of Java?
a) Platform-dependent
b) Platform-independent
c) Machine-dependent
d) Uses low-level programming

Answer
b) Platform-independent

Which of the following Python data types is immutable?
a) list
b) tuple
c) dict
d) set

Answer
b) tuple

What is the default value of a boolean variable in Java?
a) 1
b) false
c) true
d) 0

Answer
b) false

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;

Answer
a) int arr[5];

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

Answer
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[]

Answer
b) 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

Answer
a) 14

Which of the following is used to implement a method in Java?
a) def
b) public
c) void
d) function

Answer
b) public

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

Answer
a) Compares two values

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;}

Answer
a) switch (x) {case 1: break;}

In Python, how do you handle exceptions?
a) catch
b) try-catch
c) try-except
d) handle

Answer
c) try-except

In C++, what is used to output data to the console?
a) printf()
b) cout
c) echo
d) print()

Answer
b) cout

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

Answer
b) Python is a strongly typed language

Which of the following is NOT a keyword in Java?
a) extends
b) super
c) dynamic
d) final

Answer
c) dynamic

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

Answer
a) Accepts input from the user

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>

Answer
b) list = [1, 2, 3]

Which of the following Java operators is used for concatenation?
a) +
b) –
c) *
d) &

Answer
a) +

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()

Answer
d) Scanner.nextLine()

Which of the following is NOT a valid C++ loop structure?
a) for
b) while
c) foreach
d) do-while

Answer
c) foreach

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”

Answer
c) print(“Hello World”)

In Java, how is a constructor declared?
a) void ConstructorName()
b) ConstructorName()
c) class ConstructorName()
d) public ConstructorName()

Answer
b) ConstructorName()

Related Articles

Leave a Reply

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

Back to top button