wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Code Master - CN

Total questions: 53

Worksheet time: 29mins

Name
Class
Date
1.

What is the purpose of the `#include <stdio.h>` directive in C?

a)

To include standard input/output functions

b)

To define a macro

c)

To include math functions

d)

To include string manipulation functions

2.

What is the output of `printf("%d", sizeof(char))`

a)

1

b)

2

c)

4

d)

depends on compiler

3.

Which sorting algorithm has the worst-case time complexity of O(n^2)

a)

Merge Sort

b)

Quick Sort

c)

Bubble Sort

d)

Insertion Sort

4.

In a binary search tree (BST), what is the maximum number of children a node can have?

a)

3

b)

2

c)

1

d)

undefined

5.

What does FIFO stand for?

a)

First In, First Out

b)

First Input, First Output

c)

First In, First Ordered

d)

First Index, First Out

6.

Which of the following data structures is not linear

a)

Array

b)

Linked List

c)

Stack

d)

Tree

7.

What is the output of `print("hello" + 3)` in Python

a)

hello3

b)

hellohellohello

c)

Error

d)

None of the above

8.

What does the `pop()` method do on a Python list

a)

Removes the last element from the list and returns it

b)

Adds an element to the end of the list

c)

Returns the index of the specified element

d)

Sorts the list in ascending order

9.

Which of the following is not a valid way to open a file in Python

a)

open("file.txt", "r")

b)

open("file.txt", "write")

c)

open("file.txt", "a")

d)

open("file.txt", "rb")

10.

Which of the following is not a valid data type in C

a)

float

b)

boolean

c)

char

d)

double

11.

What is the purpose of the `sizeof` operator in C

a)

Returns the size of a variable in bytes

b)

Returns the value of a variable

c)

Returns the address of a variable

d)

None of the above

12.

What is the main advantage of using a hash table

a)

Constant time insertion and deletion

b)

Constant time search

c)

Constant time sorting

d)

Constant time access

13.

In a priority queue implemented using a binary heap, what is the time complexity of extracting the maximum element?

a)

O(1)

b)

O(log n)

c)

O(n)

d)

O(n log n)

14.

Which of the following is not a type of tree

a)

Binary Tree

b)

AVL Tree

c)

Linked Tree

d)

B-tree

15.

Which data structure follows the Last In, First Out (LIFO) principle

a)

Queue

b)

Stack

c)

Linked List

d)

Tree

16.

What is the time complexity of inserting an element at the end of a dynamic array (assuming no resizing is needed)

a)

O(1)

b)

O(log n)

c)

O(n)

d)

O(n^2)

17.

What is the output of `print(10 / 3)` in Python

a)

3.3333

b)

3

c)

3.0

d)

Error

18.

What does the `len()` function return in Python

a)

Number of elements in a list

b)

Length of a string

c)

Number of keys in a dictionary

d)

All of the above

19.

What is the output of `3 * 'abc'` in Python

a)

abcabcabc

b)

abcabc

c)

abc

d)

Error

20.

Which of the following is an immutable data type in Python

a)

List

b)

Dictionary

c)

Tuple

d)

Set

21.

How is Level-1 ?

a)

Dead Easy 😆

b)

Yup!!! Can do it!! 😌

c)

Hard 😱

d)

Why do you ask such questions ? 😠

22.

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)

Error

23.

In Python, which of the following is a correct way to comment a single line of code

a)

// This is a comment

b)

# This is a comment

c)

/* This is a comment */

d)

  -- This is a comment

24.

What is the correct syntax to open a file named "example.txt" for reading in Python

a)

open("example.txt", "r")

b)

open("example.txt", "w")

c)

open("example.txt", "a")

d)

open("example.txt", "rb")

25.

What will be the output of the following Python code?

x = [1, 2, 3]

y = x

y.append(4)

print(x)

a)

[1, 2, 3]

b)

[1, 2, 3, 4]

c)

[1, 2, 3, 4, 4]

d)

Error

26.

Which of the following is not a valid data type in C

a)

float

b)

double

c)

string

d)

unsigned char

27.

Consider the following C code snippet:

#include <stdio.h>

int main() {

    int arr[5] = {1, 2, 3, 4, 5};

    printf("%d", arr[5]);

    return 0;

}

What will be the output of this code?

a)

5

b)

4

c)

Error

d)

Undefined

28.

Which of the following statements is true about Python lists?

a)

Lists cannot store different data types.

b)

Lists are immutable.

c)

Lists can contain duplicate elements.

d)

Lists are accessed using curly braces `{}

29.

In C, what does the `sizeof()` operator return?

a)

The size of the variable

b)

The size of the data type

c)

The number of elements in an array

d)

The address of the variable

30.

What is the correct way to declare a function in Python

a)

function myFunction():

b)

define myFunction():

c)

def myFunction():

d)

def my_function(x :

31.

What will be the output of the following code snippet?

public class Main {

    public static void main(String[] args) {

        String str1 = "hello";

        String str2 = new String("hello");

        System.out.println(str1 == str2);

    }

}

a)

true

b)

false

c)

Compilation Error

d)

Runtime Error

32.

Which of the following is a correct way to initialize an empty list in Python?

a)

list = {}

b)

list = []

c)

list = [None]

d)

list = None

33.

What will be the output of the following C code?

#include <stdio.h>

int main() {

    int x = 0;

    for (; x < 5; x++) {

        printf("%d", x);

    }

    return 0;

}

a)

01234

b)

12345

c)

54321

d)

00000

34.

What will be the output of the following C code

#include <stdio.h>

int main() {

    int x = 5;

    if (x == 5)

        printf("Hello");

    else

        printf("World");

    return 0;

}

a)

Hello

b)

World

c)

HelloWorld

d)

No output

35.

In C, what is the output of the following code snippet?

#include <stdio.h>

int main() {

    int x = 10;

    int *ptr = &x;

    printf("%d", *ptr);

    return 0;

}

a)

10

b)

error

c)

garbage values

d)

Address of x

36.

What will be the output of the following Python code?

def foo(x, y=[]):

    y.append(x)

    return y

print(foo(1))

print(foo(2))

a)

[1] [2]

b)

[1, 2] [2]

c)

[1] [1, 2]

d)

[1] [1] [2] [2]

37.

How is Level-2?

a)

Dead Easy 😆

b)

Yup!!! Can do it!! 😌

c)

Hard 😱

d)

Why do you ask such questions ? 😠

38.

What will be the output of the following C code?

#include <stdio.h>

int main() {

    int x = 5;

    int *ptr = &x;

    printf("%d", *ptr++);

    return 0;

}

a)

5

b)

6

c)

Error

d)

Undefined

39.

Which of the following statements about linked lists is true

a)

They have constant-time access to arbitrary elements.

b)

They use contiguous memory allocation.

c)

They have O(n) time complexity for both insertion and deletion operations.

d)

They cannot be traversed in reverse.

40.

What is the time complexity of binary search in the worst case?

a)

O(1)

b)

O(log n)

c)

O(n)

d)

O(n^2)

41.

Which sorting algorithm has the best worst-case time complexity?

a)

Bubble Sort

b)

Merge Sort

c)

Quick Sort

d)

Insertion Sort

42.

What does the following C code do?

#include <stdio.h>

int main() {

    int arr[] = {1, 2, 3, 4, 5};

    int *ptr = arr + 2;

    printf("%d", *ptr);

    return 0;

}

a)

Prints 1

b)

Prints 2

c)

Prints 3

d)

Prints 4

43.

What is the output of the following Python code?

x = 5

y = 7

z = x if x > y else y

print(z)

a)

5

b)

7

c)

Error

d)

None

44.

What is the time complexity of searching in a hash table with chaining

a)

O(1)

b)

O(log n)

c)

O(n)

d)

O(n^2)

45.

What will be the output of the following C code?

#include <stdio.h>

int main() {

    char str[] = "Hello";

    printf("%c", str[5]);

    return 0;

}

a)

Error

b)

Undefined

c)

Space

d)

Null Character

46.

Which of the following data structures uses dynamic memory allocation?

a)
Queue
b)
Linked list
c)
Stack
d)
Array
47.

Which of the following statements about binary trees is true?

a)
A binary tree has only one child for each node
b)
A binary tree has a fixed depth for each node
c)
A binary tree has at most three children for each node
d)
A binary tree has at most two children for each node
48.

What will be the output of the following code snippet?

public class Main {

    public static void main(String[] args) {

        int x = 5;

        System.out.println(x++ + ++x);

    }

}

a)

10

b)

11

c)

12

d)

13

49.

Which of the following functions could be used with filter() to remove all negative numbers from a list?

a)

lambda x: x < 0

b)

lambda x: x == 0

c)

lambda x: x > 1

d)

lambda x: x % 2 == 0

50.

What is the output of the following code?

from functools import reduce

lst = [1, 2, 3, 4, 5]

result = reduce(lambda x, y: x + y, lst)

print(result)

a)

15

b)

20

c)

120

d)

30

51.

What is the time complexity of inserting an element into a heap?

a)

O(1)

b)

O(log n)

c)

O(n)

d)

O(n^2)

52.

What will be the output of the following Python code?

def my_func(x):

    if x > 0:

        return "Positive"

    elif x < 0:

        return "Negative"

    else:

        return "Zero"

print(my_func(0))

a)
Zero
b)
Positive
c)
Error
d)
None
53.

How is Code Master ?

a)

Not Bad

🙂

b)

Good

✌🏻

c)

Exciting

🎉

d)

Super Exciting

🥳🎉💃🏻