WorksheetsPython and C Programming Quiz
Total questions: 50
Worksheet time: 50mins
What is the output of print(2 * 3)?
5
6
23
None
Which keyword is used to define a function?
func
define
def
function
What is the output of print(type("Hello"))?
<class 'str'>
<class 'int'>
<class 'char'>
<class 'text'>
Which of the following is a valid variable name?
2name
name_1
@name
name-1
What does len([1, 2, 3]) return?
1
2
3
Error
Which data type is mutable?
Tuple
String
List
Integer
How do you start a comment in Python?
//
#
/*
--
What is the output of print(10 // 3)?
3.33
3
3.0
4
Which function is used to get user input?
input()
raw_input()
scan()
read()
What is the output of bool([])?
True
False
None
Error
How do you create a dictionary?
{}
[]
()
<>
Which statement is used for exception handling?
catch
try-except
error
handle
What does list(range(3)) return?
[1, 2, 3]
[0, 1, 2]
[0, 1, 2, 3]
None
Which method removes the last item from a list?
delete()
remove()
pop()
clear()
Which loop is used for iterating over a sequence?
while
for
do-while
foreach
What is the output of print(bool("False"))?
True
False
None
Error
Which module is used for working with regular expressions?
regex
re
regexp
express
What does lambda x: x + 2 do?
Creates a function
Adds 2 to x
Returns a lambda function
All of the above
Which function is used to open a file in Python?
open()
read()
write()
access()
What is set([1,2,2,3,4])?
{1, 2, 2, 3, 4}
{1, 2, 3, 4}
[1, 2, 3, 4]
(1, 2, 3, 4)
Which function sorts a list in-place?
sorted()
sort()
order()
arrange()
Which method returns the index of an element in a list?
locate()
find()
index()
search()
What will bool(None) return?
True
False
None
Error
Which operator is used for exponentiation in Python?
^
**
%%
//
Which statement is used to exit a loop immediately?
return
continue
break
exit
What will be the output of printf("%d", 10 + 5 * 2);?
20
30
15
10
Which of the following is true for C language?
It is a high-level language
It is a low-level language
It is both high-level and low-level
None of the above
How many bytes does the float data type take in memory (typically on a 32-bit system)?
2
4
8
16
Which of the following functions is used to read a string from the console?
gets()
scanf()
fgets()
Both A and C
What will be the output of the following code? int x = 5; printf("%d %d", x++, ++x);
5 6
6 7
Undefined behavior
Compiler error
What is the return type of the malloc() function?
void
int
void*
char*
What is the correct syntax to declare a pointer to an integer?
int ptr;
int *ptr;
*int ptr;
ptr *int;
What is the purpose of the sizeof operator in C?
To get the size of a variable
To allocate memory dynamically
To find the size of an array
Both A and C
Which header file is required for memory allocation functions like malloc() and calloc()?
stdlib.h
stdio.h
malloc.h
memory.h
What will be the output of the following code? int a = 10, b = 20; int *ptr = &a; ptr = &b; printf("%d", *ptr);
10
20
Address of b
None of the above
What does the break statement do inside a loop?
Terminates the loop immediately
Skips the current iteration
Returns to the beginning of the loop
Causes an infinite loop
What is the difference between struct and union in C?
A struct stores all members separately, while a union shares the same memory for all members.
A struct can store only integers, while a union can store any type.
A struct can have functions inside it, while a union cannot.
There is no difference.
How do you properly deallocate memory allocated with malloc()?
free()
delete
clear()
None of the above
Which of the following is a correct declaration for a function that takes an integer and returns a float?
int func(float x);
float func(int x);
void func(int x);
func(int) float;
What will be the output of the following? int x = 5; printf("%d", x = x + 1);
5
6
Compilation error
Undefined behavior
Which of the following loops is guaranteed to execute at least once?
for
while
do-while
None
What will be the output of printf("%c", 65);?
65
A
Compilation error
Undefined behavior
What will happen if you access an array index out of bounds in C?
Compiler error
Runtime error
Undefined behavior
Segmentation fault
What is the correct way to initialize an array in C?
int arr[3] = {1, 2, 3};
int arr[] = {1, 2, 3};
Both A and B
None
How do you open a file in read mode in C?
fopen("file.txt", "r");
open("file.txt", "r");
file_open("file.txt", "r");
read("file.txt", "r");
Which function is used to compare two strings in C?
strcmp()
strcomp()
compare()
str_compare()
What will be the output of the following? int a = 10, b = 20; printf("%d", a > b ? a : b);
10
20
Compilation error
None
What is a correct way to define a pointer to an array?
int *ptr;
int arr[] = {1,2,3}, *ptr = arr;
int ptr[] = &arr;
int ptr = arr[];
What will be the value of sizeof(char) in C?
2
1
4
8
What will be the output of printf("%d", 'A');?
A
65
Compilation error
Undefined
