wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Code debugging - Round 1

Total questions: 30

Worksheet time: 10mins

Name
Class
Date
1.

1.What will be the output of the following C code?

int main()

{

int x = 10;

if (x = 5)

{

printf("True");

}

else

{

printf("False");

}

   return 0;

 }

a)
Segmentation Fault
b)
False
c)
True
d)
Error
2.

Which of the following statements is true about the C programming language's malloc() function?

a)

It automatically initializes the memory allocated to zero.

b)

It allocates memory from the stack.

c)

It returns a pointer to the first byte of the allocated memory.

d)

It is a standard library function for dynamic memory allocation in C++ only.

3.

What will be the output of the following C code?

#include <stdio.h>

int main()

{

char str[] = "Hello";

str[0] = 'J';

printf("%s", str);

return 0;

}

a)

Hello

b)

Jello

c)

Error

d)

Undefined behavior

4.

Which Python statement creates an empty set?

a)

set()

b)

[]

c)

{}  

d)

empty()

5.

What will the following C code print?

int x = 5;

printf("%d %d %d", x++, ++x, x);

a)

5 7 6

b)

6 7 6

c)

5 6 6

d)

Undefined behavior

6.

In Python, what is the purpose of the lambda function?

a)

To define an anonymous function in a single line.

b)

To define a function with a fixed number of arguments.

c)

To define a function with variable arguments.

d)

To make a function that returns multiple values.

7.

Which of the following Python methods is used to remove an item from a list?

a)

list.delete()

b)

list.pop()

c)

list.remove()

d)

 list.clear()

8.

Which of the following C statements is correct for allocating memory for an array of 10 integers?

a)

int *arr = malloc(10);

b)

int *arr = malloc(10 * sizeof(int));

c)

int arr = malloc(10 * sizeof(int));

d)

int arr[10] = malloc(sizeof(int));

9.

What will be the result of the following Python code?

python

a = [1, 2, 3]

a = a * 2

print(a)

a)

[1, 2, 3, 1, 2, 3]

b)

[1, 2, 3]

c)

[1, 2, 3, 4, 5, 6]  

d)

Error

10.

Which of the following is the correct syntax for a comment in C?

a)

# comment

b)

/* comment */

c)

// comment

d)

Both B and C

11.

Which of the following Python data types is immutable?

a)

List

b)

Dictionary

c)

String

d)

Set

12.

What is the default value of an uninitialized variable in C?

a)

0

b)

NULL

c)

Undefined

d)

NaN

13.

In C, what is the purpose of the void keyword?

a)

It is used to define a function that does not return a value.

b)

It is used to define a variable of any data type.

c)

It is used to define a function that returns a pointer.

d)

It is used to define an empty array.

14.

Which of the following Python statements is used to remove an element from a dictionary?

a)

del dict[key]

b)

dict.delete(key)

c)

dict.remove(key)

d)

dict.pop(key)

15.

In Python, which method is used to get the length of a list?

a)

length(list)

b)

len(list)

c)

list.length()

d)

size(list)

16.

In C, which function is used to read a character from the user?

a)

scanf()

b)

getch()

c)

getchar()

d)

None of the above

17.

What is the default return type of a function in C if none is specified?

a)

int

b)

void

c)

float

d)

None of the above

18.

int x = 10;

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

a)

110

b)

Undefined behavior

c)

121

d)

100

19.

In C, which of the following statements is true about calloc() and malloc()?

a)

Both initialize allocated memory to zero

b)

Only calloc() initializes memory to zero

c)

Only malloc() initializes memory to zero

d)

Neither initialize memory to zero

20.

In C, what does sizeof("hello") return?

a)

5

b)

6

c)

4

d)

7

21.

x = [1, 2, 3]

y = x

y.append(4)

print(x)

a)

[1, 2, 3]

b)

[1, 2, 3, 4]

c)

[4]

d)

Error

22.

In Python, which of the following is used to convert a list to a tuple?

a)

list()

b)

tuple()

c)

set()

d)

convert()

23.

int x = 4, y = 3;

if (x < y || ++x == 5)

printf("%d", x)

else

printf("%d", y);

a)

4

b)

3

c)

5

d)

Error

24.

What is the size of a pointer variable in a 32-bit system?

a)

4 bytes

b)

8 bytes

c)

16 bytes

d)

2 bytes

25.

What does the sizeof() operator in C return?

a)

The size of a variable in bits.

b)

The size of a variable in bytes.

c)

The length of an array.

d)

The address of a variable.

26.

What is the output of the following Python code?

def func(x, y=[]):

y.append(x)

return y

print(func(1))

print(func(2, []))

print(func(3))

a)

[1] [2] [3]

b)

[1] [2] [3, 1]

c)

[1] [2] [3, 2]

d)

[1, 3] [2] [3]

27.

What will be the output of the following Python code?

a = {1, 2, 3}

b = {3, 4, 5}

print(a & b, a | b, a ^ b)

a)

{3} {1, 2, 3, 4, 5} {1, 2, 4, 5}

b)

{3} {3, 4, 5} {1, 2}

c)

{1, 2} {3, 4, 5} {1, 2, 4, 5}

d)

{3} {1, 2, 3} {4, 5}

28.

What will be the output of this Python code?

def func(a, b=10):

return a + b

def func(a, b):

return a * b

print(func(2, 3))

a)

5

b)

6

c)

None

d)

Type Error

29.

What will be the output of the following C code?

int x = 3;

int y = 4;

int *p = &x;

int **q = &p;

printf("%d", **q + y);

a)

7

b)

10

c)

3

d)

8

30.

What will be the output of the following C code?

int a = 10;

int b = 20;

int *ptr = &a;

*ptr = b;

printf("%d %d", a, b);

a)

10 20

b)

20 20

c)

10 10

d)

Error