wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python and C Programming Quiz

Total questions: 50

Worksheet time: 50mins

Name
Class
Date
1.

What is the output of print(2 * 3)?

a)

5

b)

6

c)

23

d)

None

2.

Which keyword is used to define a function?

a)

func

b)

define

c)

def

d)

function

3.

What is the output of print(type("Hello"))?

a)

<class 'str'>

b)

<class 'int'>

c)

<class 'char'>

d)

<class 'text'>

4.

Which of the following is a valid variable name?

a)

2name

b)

name_1

c)

@name

d)

name-1

5.

What does len([1, 2, 3]) return?

a)

1

b)

2

c)

3

d)

Error

6.

Which data type is mutable?

a)

Tuple

b)

String

c)

List

d)

Integer

7.

How do you start a comment in Python?

a)

//

b)

#

c)

/*

d)

--

8.

What is the output of print(10 // 3)?

a)

3.33

b)

3

c)

3.0

d)

4

9.

Which function is used to get user input?

a)

input()

b)

raw_input()

c)

scan()

d)

read()

10.

What is the output of bool([])?

a)

True

b)

False

c)

None

d)

Error

11.

How do you create a dictionary?

a)

{}

b)

[]

c)

()

d)

<>

12.

Which statement is used for exception handling?

a)

catch

b)

try-except

c)

error

d)

handle

13.

What does list(range(3)) return?

a)

[1, 2, 3]

b)

[0, 1, 2]

c)

[0, 1, 2, 3]

d)

None

14.

Which method removes the last item from a list?

a)

delete()

b)

remove()

c)

pop()

d)

clear()

15.

Which loop is used for iterating over a sequence?

a)

while

b)

for

c)

do-while

d)

foreach

16.

What is the output of print(bool("False"))?

a)

True

b)

False

c)

None

d)

Error

17.

Which module is used for working with regular expressions?

a)

regex

b)

re

c)

regexp

d)

express

18.

What does lambda x: x + 2 do?

a)

Creates a function

b)

Adds 2 to x

c)

Returns a lambda function

d)

All of the above

19.

Which function is used to open a file in Python?

a)

open()

b)

read()

c)

write()

d)

access()

20.

What is set([1,2,2,3,4])?

a)

{1, 2, 2, 3, 4}

b)

{1, 2, 3, 4}

c)

[1, 2, 3, 4]

d)

(1, 2, 3, 4)

21.

Which function sorts a list in-place?

a)

sorted()

b)

sort()

c)

order()

d)

arrange()

22.

Which method returns the index of an element in a list?

a)

locate()

b)

find()

c)

index()

d)

search()

23.

What will bool(None) return?

a)

True

b)

False

c)

None

d)

Error

24.

Which operator is used for exponentiation in Python?

a)

^

b)

**

c)

%%

d)

//

25.

Which statement is used to exit a loop immediately?

a)

return

b)

continue

c)

break

d)

exit

26.

What will be the output of printf("%d", 10 + 5 * 2);?

a)

20

b)

30

c)

15

d)

10

27.

Which of the following is true for C language?

a)

It is a high-level language

b)

It is a low-level language

c)

It is both high-level and low-level

d)

None of the above

28.

How many bytes does the float data type take in memory (typically on a 32-bit system)?

a)

2

b)

4

c)

8

d)

16

29.

Which of the following functions is used to read a string from the console?

a)

gets()

b)

scanf()

c)

fgets()

d)

Both A and C

30.

What will be the output of the following code? int x = 5; printf("%d %d", x++, ++x);

a)

5 6

b)

6 7

c)

Undefined behavior

d)

Compiler error

31.

What is the return type of the malloc() function?

a)

void

b)

int

c)

void*

d)

char*

32.

What is the correct syntax to declare a pointer to an integer?

a)

int ptr;

b)

int *ptr;

c)

*int ptr;

d)

ptr *int;

33.

What is the purpose of the sizeof operator in C?

a)

To get the size of a variable

b)

To allocate memory dynamically

c)

To find the size of an array

d)

Both A and C

34.

Which header file is required for memory allocation functions like malloc() and calloc()?

a)

stdlib.h

b)

stdio.h

c)

malloc.h

d)

memory.h

35.

What will be the output of the following code? int a = 10, b = 20; int *ptr = &a; ptr = &b; printf("%d", *ptr);

a)

10

b)

20

c)

Address of b

d)

None of the above

36.

What does the break statement do inside a loop?

a)

Terminates the loop immediately

b)

Skips the current iteration

c)

Returns to the beginning of the loop

d)

Causes an infinite loop

37.

What is the difference between struct and union in C?

a)

A struct stores all members separately, while a union shares the same memory for all members.

b)

A struct can store only integers, while a union can store any type.

c)

A struct can have functions inside it, while a union cannot.

d)

There is no difference.

38.

How do you properly deallocate memory allocated with malloc()?

a)

free()

b)

delete

c)

clear()

d)

None of the above

39.

Which of the following is a correct declaration for a function that takes an integer and returns a float?

a)

int func(float x);

b)

float func(int x);

c)

void func(int x);

d)

func(int) float;

40.

What will be the output of the following? int x = 5; printf("%d", x = x + 1);

a)

5

b)

6

c)

Compilation error

d)

Undefined behavior

41.

Which of the following loops is guaranteed to execute at least once?

a)

for

b)

while

c)

do-while

d)

None

42.

What will be the output of printf("%c", 65);?

a)

65

b)

A

c)

Compilation error

d)

Undefined behavior

43.

What will happen if you access an array index out of bounds in C?

a)

Compiler error

b)

Runtime error

c)

Undefined behavior

d)

Segmentation fault

44.

What is the correct way to initialize an array in C?

a)

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

b)

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

c)

Both A and B

d)

None

45.

How do you open a file in read mode in C?

a)

fopen("file.txt", "r");

b)

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

c)

file_open("file.txt", "r");

d)

read("file.txt", "r");

46.

Which function is used to compare two strings in C?

a)

strcmp()

b)

strcomp()

c)

compare()

d)

str_compare()

47.

What will be the output of the following? int a = 10, b = 20; printf("%d", a > b ? a : b);

a)

10

b)

20

c)

Compilation error

d)

None

48.

What is a correct way to define a pointer to an array?

a)

int *ptr;

b)

int arr[] = {1,2,3}, *ptr = arr;

c)

int ptr[] = &arr;

d)

int ptr = arr[];

49.

What will be the value of sizeof(char) in C?

a)

2

b)

1

c)

4

d)

8

50.

What will be the output of printf("%d", 'A');?

a)

A

b)

65

c)

Compilation error

d)

Undefined