WorksheetsBRAIN STACK
Total questions: 40
Worksheet time: 40mins
What is the output of: int a[5]={1,2,3,4,5}; printf("%d", a[2]);
1
2
3
5
What is the output? int x=10; int *p=&x; printf("%d", *p);
10
Address of x
Error
Garbage
Which operator is used to access structure members?
.
->
&
*
Size of pointer on a 64-bit system is:
2
4
8
16
What does * denote in pointers?
Address
Value at address
Variable
Function
What is the output of: int x=10; if(x=5) printf("Hello"); else printf("World");
Hello
World
Error
No output
The break statement is used to:
Skip next iteration
Exit from loop/switch
Stop the program
Pause loop temporarily
int main() { int a = 5, b = 3; printf("%d", a + b * 2); return 0; }
16
11
10
13
Predict the output:
#include
A) 5 6
B) 6 7
C) 5 7
D) 6 5
what is the correct output:
#include
A) 0 1 2 3 4
B) 0 1 2
C) 0 1 2 3
D) 1 2 3
What will be the output of print("Python"[::-1])?
Python
nohtyP
What is the output of set([1,2,2,3])?
[1,2,2,3]
{1,2,3}
{1,2,2,3}
Error
Which of the following is used to iterate over a sequence in Python?
for
while
loop
iterate
Which of the following will raise an exception if the key does not exist in a dictionary?
dict.get(key)
dict[key]
dict.keys()
dict.values()
Which of the following is correct to read input from the user?
input()
scanf()
cin >>
read()
Which of the following is used for multi-line comments in Python?
'''comment '''
""" comment """
Both a and b
// comment
What will be the output of: x = "Hello"; print(x[1])?
H
e
l
o
What will be the output of: print(2**3)?
6
8
9
5
What will be the output of: for i in range(3): print(i)?
a) 1 2 3
b) 0 1 2
c) 0 1 2 3
d) 1 2
What will be the output of: x = "abc"; y = x.upper(); print(y)?
abc
ABC
Abc
aBC
Which of the following is a non-linear data structure?
Stack
Queue
Linked List
Tree
Which of the following is a dynamic data structure?
Array
Linked List
Both a and b
None
What is the time complexity of accessing an element in an array?
O(1)
O(n)
O(log n)
O(n2)
Which of the following is not a type of linked list?
Singly Linked List
Doubly Linked List
Circular Linked List
Balanced Linked List
Which traversal visits nodes in left-right-root order in a binary tree?
Preorder
Inorder
Postorder
Level order
What is the maximum number of nodes in a binary tree of height h?
2h−1
2h
h2
h+1
Which of the following is true for a full binary tree?
Every node has 0 or 1 child
Every node has 0 or 2 children
Every node has 2 children only
Only leaf nodes have 2 children
Which of the following is used to represent sparse graphs efficiently?
Adjacency matrix
Adjacency list
Linked list
Array
What is the time complexity of inserting an element in a BST?
O(1)
O(n)
O(log n)
O(n log n)
Which of the following is true about a stack?
FIFO
LIFO
Random
Circular
Which of the following is a primitive data type in Java?
String
boolean
Array
Class
What is the size of int in Java?
2 bytes
4 bytes
8 bytes
Depends on the system
Which of the following is correct way to declare an array?
int arr[];
int[] arr;
Both a and b
arr int[];
Which of the following is correct syntax for if statement?
if x > y {}
if (x > y) {}
if x > y: {}
if (x > y): {}
What is the result of 5 + "5" in Java?
10
"55"
5
Error
Which keyword is used to prevent inheritance of a class?
stop
final
static
private
What is the default value of an instance variable of type int?
0
1
null
undefined
Which of the following is a valid way to declare a 2D array?
int[][] arr = new int[2][3];
int arr[2][3];
int arr = new int[2][3];
array int[2][3];
What is the output of: System.out.println(10 + 20 + "Hello");?
10Hello20
30Hello
Hello30
Error
What will be output of System.out.println(10 / 3);?
3.33
3
3.0
4
