wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

BRAIN STACK

Total questions: 40

Worksheet time: 40mins

Name
Class
Date
1.

What is the output of: int a[5]={1,2,3,4,5}; printf("%d", a[2]);

a)

1

b)

2

c)

3

d)

5

2.

What is the output? int x=10; int *p=&x; printf("%d", *p);

a)

10

b)

Address of x

c)

Error

d)

Garbage

3.

Which operator is used to access structure members?

a)

.

b)

->

c)

&

d)

*

4.

Size of pointer on a 64-bit system is:

a)

2

b)

4

c)

8

d)

16

5.

What does * denote in pointers?

a)

Address

b)

Value at address

c)

Variable

d)

Function

6.

What is the output of: int x=10; if(x=5) printf("Hello"); else printf("World");

a)

Hello

b)

World

c)

Error

d)

No output

7.

The break statement is used to:

a)

Skip next iteration

b)

Exit from loop/switch

c)

Stop the program

d)

Pause loop temporarily

8.

int main() { int a = 5, b = 3; printf("%d", a + b * 2); return 0; }

a)

16

b)

11

c)

10

d)

13

9.

Predict the output: #include int main() { int x = 5; printf("%d %d", x++, ++x); return 0; }

a)

A) 5 6

b)

B) 6 7

c)

C) 5 7

d)

D) 6 5

10.

what is the correct output: #include int main() { int i; for(i = 0; i < 5; i++) { if(i == 3) break; printf("%d ", i); } return 0; }

a)

A) 0 1 2 3 4

b)

B) 0 1 2

c)

C) 0 1 2 3

d)

D) 1 2 3

11.

What will be the output of print("Python"[::-1])?

a)

Python

b)

nohtyP

12.

What is the output of set([1,2,2,3])?

a)

[1,2,2,3]

b)

{1,2,3}

c)

{1,2,2,3}

d)

Error

13.

Which of the following is used to iterate over a sequence in Python?

a)

for

b)

while

c)

loop

d)

iterate

14.

Which of the following will raise an exception if the key does not exist in a dictionary?

a)

dict.get(key)

b)

dict[key]

c)

dict.keys()

d)

dict.values()

15.

Which of the following is correct to read input from the user?

a)

input()

b)

scanf()

c)

cin >>

d)

read()

16.

Which of the following is used for multi-line comments in Python?

a)

'''comment '''

b)

""" comment """

c)

Both a and b

d)

// comment

17.

What will be the output of: x = "Hello"; print(x[1])?

a)

H

b)

e

c)

l

d)

o

18.

What will be the output of: print(2**3)?

a)

6

b)

8

c)

9

d)

5

19.

What will be the output of: for i in range(3): print(i)?

a)

a) 1 2 3

b)

b) 0 1 2

c)

c) 0 1 2 3

d)

d) 1 2

20.

What will be the output of: x = "abc"; y = x.upper(); print(y)?

a)

abc

b)

ABC

c)

Abc

d)

aBC

21.

Which of the following is a non-linear data structure?

a)

Stack

b)

Queue

c)

Linked List

d)

Tree

22.

Which of the following is a dynamic data structure?

a)

Array

b)

Linked List

c)

Both a and b

d)

None

23.

What is the time complexity of accessing an element in an array?

a)

O(1)

b)

O(n)

c)

O(log n)

d)

O(n2)O(n^2)

24.

Which of the following is not a type of linked list?

a)

Singly Linked List

b)

Doubly Linked List

c)

Circular Linked List

d)

Balanced Linked List

25.

Which traversal visits nodes in left-right-root order in a binary tree?

a)

Preorder

b)

Inorder

c)

Postorder

d)

Level order

26.

What is the maximum number of nodes in a binary tree of height h?

a)

2h12^h - 1

b)

2h2^h

c)

h2h^2

d)

h+1

27.

Which of the following is true for a full binary tree?

a)

Every node has 0 or 1 child

b)

Every node has 0 or 2 children

c)

Every node has 2 children only

d)

Only leaf nodes have 2 children

28.

Which of the following is used to represent sparse graphs efficiently?

a)

Adjacency matrix

b)

Adjacency list

c)

Linked list

d)

Array

29.

What is the time complexity of inserting an element in a BST?

a)

O(1)

b)

O(n)

c)

O(log n)

d)

O(n log n)

30.

Which of the following is true about a stack?

a)

FIFO

b)

LIFO

c)

Random

d)

Circular

31.

Which of the following is a primitive data type in Java?

a)

String

b)

boolean

c)

Array

d)

Class

32.

What is the size of int in Java?

a)

2 bytes

b)

4 bytes

c)

8 bytes

d)

Depends on the system

33.

Which of the following is correct way to declare an array?

a)

int arr[];

b)

int[] arr;

c)

Both a and b

d)

arr int[];

34.

Which of the following is correct syntax for if statement?

a)

if x > y {}

b)

if (x > y) {}

c)

if x > y: {}

d)

if (x > y): {}

35.

What is the result of 5 + "5" in Java?

a)

10

b)

"55"

c)

5

d)

Error

36.

Which keyword is used to prevent inheritance of a class?

a)

stop

b)

final

c)

static

d)

private

37.

What is the default value of an instance variable of type int?

a)

0

b)

1

c)

null

d)

undefined

38.

Which of the following is a valid way to declare a 2D array?

a)

int[][] arr = new int[2][3];

b)

int arr[2][3];

c)

int arr = new int[2][3];

d)

array int[2][3];

39.

What is the output of: System.out.println(10 + 20 + "Hello");?

a)

10Hello20

b)

30Hello

c)

Hello30

d)

Error

40.

What will be output of System.out.println(10 / 3);?

a)

3.33

b)

3

c)

3.0

d)

4