You are on page 1of 73

INDIAN SOCITY FOR

TECHNICAL EDUCATION

Tech QUIZ
Which of the following is not a primitive
data type in C/C++?
a) int b)
b) float
c) string
d) char
Answer: c) string
In Python, which keyword is used to
define a function?
a) def
b) function
c) define
d) define_function
Answer: a) def
What is the output of the following C code snippet?
#include <stdio.h>
int main() {
int x = 5;
printf("%d", x++);
return 0;
}

a) 5
b)6
c) 4
d) Compiler Error
Answer: a) 5
Which data type is used to store a single
character in C/C++?
a) Char
b) Character
c) String
d) chr
Answer: a) char
What is the output of the following C++ code?
#include <iostream>
using namespace std;
int main() {
int x = 10;
int y = 5;
cout << (x > y ? "x is greater" : "y is greater");
return 0;
}

a) x is greater
b) y is greater
c) 10
d) 5
Answer: a) x is greater
Which symbol is used to indicate the start of
a comment line in Python?
a) //
b) #
c) /
d) /* */
Answer: b) #
What will be the output of the following C code?
#include <stdio.h>
int main() {
int a = 5;
int b = 10;
printf("%d", a & b);
return 0;
}

a) 15
b) 0
c) 5
d) 10
Answer: b) 0
In C++, how is memory allocated
dynamically?

a) malloc()
b) calloc()
c) new
d) All of the above
Answer: d) All of the above
What is the output of the following C code snippet?

#include <stdio.h>
int main() {
int i = 0;
while (i < 5) {
printf("%d ", i);
i++;
}
return 0;
}

a) 01234
b) 12345
c) 0123
d) 1234
Answer: a) 0 1 2 3 4
Which of the following is a valid variable name in
Python?

a) my_variable
b) 123variable
c) variable#123
d) $variable
Answer: a) my_variable
What does the "break" statement do in a loop in C/C++?

a) Ends the loop immediately


b) Skips the current iteration and continues with the next
iteration
c) Exits the program
d) None of the above
Answer: a) Ends the loop immediately
What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main() {
int x = 5;
cout << "Value of x is: " << x++ << endl;
cout << "Value of x is: " << ++x << endl;
return 0;}

a) Value of x is: 5 Value of x is: 6


b) Value of x is: 6 Value of x is: 7
c) Value of x is: 5 Value of x is: 7
d) Value of x is: 6 Value of x is: 6
Answer: c) Value of x is: 5, Value of x is: 7
In Python, how do you access the last element of a list named
my_list?

a) my_list[-1]
b) my_list[last]
c) my_list.end()
d) my_list.last()
Answer: a) my_list[-1]
What is the output of the following Python code?

print(3 * 'un' + 'ium’)

a)unununium
b)uniumuniumunium
c)ununununium
d)None of the above
Answer: a) unununium
What is the correct way to declare a constant in Python?

a)constant x = 5;
b)define const x = 5;
c)const x = 5;
d)x = 5 (constant)
Answer: c) const x = 5;
In C, what does the "sizeof" operator return?

a) Size of the variable


b) Size of the data type
c) Size of the memory allocated
d) Size of the array
Answer: c) Size of the memory
allocated
In Python, what is the correct way to check if two
variables point to the same object?

a) using ==
b) using !=
c) using is
d) using is not
Answer: c) using is
Which of the following is a valid way to declare a
string in C/C++?

a) string myString = "Hello";


b) char myString = "Hello";
c) char myString[] = "Hello";
d) string myString[] = "Hello";
Answer: c) char myString[] = "Hello";
In Python, which keyword is used to define a
class method?
a) classmethod
b) method
c) func
d) cls
Answer: a) classmethod
In C, which header file should be included to perform
dynamic memory allocation?

a)<stdlib.h>
b) <memory.h>
c) <malloc.h>
d) <alloc.h>
Answer: a) <stdlib.h>
2. What is the result of the expression 5 & 3 in C/C+
+?

a) 1
b) 3
c) 5
d) 0
Answer: a) 1
Which of the following statements is true regarding the
"static" keyword in C/C++?

a) It makes a variable local to a function


b) It makes a variable retain its value between function
calls
c) It makes a variable accessible only within a specific
file
d) It makes a variable global
Answer: b) It makes a variable retain its value between
function calls
What does the "virtual" keyword do in C++?

a) It indicates that a function can be overridden in a


derived class.
b) It indicates that a function cannot be overridden in a
derived class.
c) It indicates that a function is declared in a base class but
defined in a derived class.
d) It indicates that a function is static.
Answer: a) It indicates that a function can be
overridden in a derived class.
What is a segmentation fault in C/C++?

a) It occurs when a program tries to access memory outside the


bounds of an array.
b) It occurs when a program tries to divide by zero.
c) It occurs when a program tries to access a NULL pointer.
d) It occurs when a program exceeds its maximum stack size.
Answer: a) It occurs when a program tries to access memory
outside the bounds of an array.
In C++, what is the purpose of the ‘typeid’ operator?

a) It returns the size of a data type in bytes.


b) It returns the type information of an object.
c) It returns the memory address of an object.
d) It returns the type of a variable as a string.
Answer: b) It returns the type information of an object
What is a lambda function in C++?

a) A function defined within another function.


b) A function with no return type.
c) A function that can be passed as an argument to
another function.
d) A function that can be used to initialize variables.
Answer: a) A function defined within another
function.
What is the purpose of the explicit keyword in C++?

a) It indicates that a constructor is called implicitly.


b) It indicates that a constructor is called explicitly.
c) It prevents automatic type conversions in constructor
calls.
d) It allows automatic type conversions in constructor
calls.
Answer: c) It prevents automatic type conversions in
constructor calls.
What is a smart pointer in C++?

a) A pointer that automatically increments its value when


dereferenced.
b) A pointer that automatically deallocates memory when it goes
out of scope.
c) A pointer that automatically manages its memory allocation
and deallocation.
d) A pointer that automatically converts between different data
types.
Answer: c) A pointer that automatically manages its memory
allocation and deallocation
What is an abstract class in C++?

a) A class that cannot be instantiated and contains at least one


pure virtual function.
b) A class that contains only static member functions.
c) A class that contains only private member functions.
d) A class that cannot be inherited by other classes.
Answer: a) A class that cannot be instantiated and contains at least one
pure virtual function.
What is a reference variable in C++?

a) A variable that holds the memory address of another variable.


b) A variable that cannot be modified after initialization.
c) An alias for another variable.
d) A variable that contains the value of another variable.
Answer: c) An alias for another variable
What is the purpose of the std::move function in C++?

a) It returns the size of an object in bytes.


b) It moves the contents of an object to another object.
c) It copies the contents of an object to another object.
d) It swaps the contents of two objects.
Answer: b) It moves the contents of an object to another
object.
Which is correct ?

a) Pointers can be NULL, while references cannot.


b) References can be reassigned to refer to different objects, while
pointers cannot.
c) References can be dereferenced using the * operator, while
pointers cannot.
d) Pointers are more efficient than references.
Answer: a) Pointers can be NULL, while references
cannot.
What is the output of the following Python code?

my_list = [1, 2, 3, 4, 5]
result = [x * 2 for x in my_list if x % 2 == 0]
print(result)

a) [2, 4, 6, 8, 10]
b) [4, 8]
c) [1, 4, 9, 16, 25]
d) [2, 4, 6, 8]
Answer: b) [4, 8]
Which of the following is a correct way to define a function in Python?

a) def my_function:
print("Hello")
b) def my_function():
print("Hello")
c) def my_function
print("Hello")
d) function my_function():
print("Hello")
Answer: b) def my_function():
print("Hello")
In Python, what is the purpose of the __init__ method in a class?

a) It is called when an object is created from the class and allows the
class to initialize attributes.
b) It is called when an object is deleted from the class and allows the
class to clean up resources.
c) It is called when an object is modified and allows the class to
update attributes.
d) It is called when an object is accessed from the class and allows
the class to retrieve attributes.
Answer: a) It is called when an object is created from the class
and allows the class to initialize attributes.
What is the purpose of the super() function in Python?

a) It returns the current module's name.


b) It returns the parent class of a class.
c) It returns the current time.
d) It returns the next element in an iterator.
Answer: b) It returns the parent class of a class.

You might also like