Font size
WorksheetsCode debugging - Round 1
Total questions: 30
Worksheet time: 10mins
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;
}
Which of the following statements is true about the C programming language's malloc() function?
It automatically initializes the memory allocated to zero.
It allocates memory from the stack.
It returns a pointer to the first byte of the allocated memory.
It is a standard library function for dynamic memory allocation in C++ only.
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;
}
Hello
Jello
Error
Undefined behavior
Which Python statement creates an empty set?
set()
[]
{}
empty()
What will the following C code print?
int x = 5;
printf("%d %d %d", x++, ++x, x);
5 7 6
6 7 6
5 6 6
Undefined behavior
In Python, what is the purpose of the lambda function?
To define an anonymous function in a single line.
To define a function with a fixed number of arguments.
To define a function with variable arguments.
To make a function that returns multiple values.
Which of the following Python methods is used to remove an item from a list?
list.delete()
list.pop()
list.remove()
list.clear()
Which of the following C statements is correct for allocating memory for an array of 10 integers?
int *arr = malloc(10);
int *arr = malloc(10 * sizeof(int));
int arr = malloc(10 * sizeof(int));
int arr[10] = malloc(sizeof(int));
What will be the result of the following Python code?
python
a = [1, 2, 3]
a = a * 2
print(a)
[1, 2, 3, 1, 2, 3]
[1, 2, 3]
[1, 2, 3, 4, 5, 6]
Error
Which of the following is the correct syntax for a comment in C?
# comment
/* comment */
// comment
Both B and C
Which of the following Python data types is immutable?
List
Dictionary
String
Set
What is the default value of an uninitialized variable in C?
0
NULL
Undefined
NaN
In C, what is the purpose of the void keyword?
It is used to define a function that does not return a value.
It is used to define a variable of any data type.
It is used to define a function that returns a pointer.
It is used to define an empty array.
Which of the following Python statements is used to remove an element from a dictionary?
del dict[key]
dict.delete(key)
dict.remove(key)
dict.pop(key)
In Python, which method is used to get the length of a list?
length(list)
len(list)
list.length()
size(list)
In C, which function is used to read a character from the user?
scanf()
getch()
getchar()
None of the above
What is the default return type of a function in C if none is specified?
int
void
float
None of the above
int x = 10;
printf("%d", x++ * ++x);
110
Undefined behavior
121
100
In C, which of the following statements is true about calloc() and malloc()?
Both initialize allocated memory to zero
Only calloc() initializes memory to zero
Only malloc() initializes memory to zero
Neither initialize memory to zero
In C, what does sizeof("hello") return?
5
6
4
7
x = [1, 2, 3]
y = x
y.append(4)
print(x)
[1, 2, 3]
[1, 2, 3, 4]
[4]
Error
In Python, which of the following is used to convert a list to a tuple?
list()
tuple()
set()
convert()
int x = 4, y = 3;
if (x < y || ++x == 5)
printf("%d", x)
else
printf("%d", y);
4
3
5
Error
What is the size of a pointer variable in a 32-bit system?
4 bytes
8 bytes
16 bytes
2 bytes
What does the sizeof() operator in C return?
The size of a variable in bits.
The size of a variable in bytes.
The length of an array.
The address of a variable.
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))
[1] [2] [3]
[1] [2] [3, 1]
[1] [2] [3, 2]
[1, 3] [2] [3]
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)
{3} {1, 2, 3, 4, 5} {1, 2, 4, 5}
{3} {3, 4, 5} {1, 2}
{1, 2} {3, 4, 5} {1, 2, 4, 5}
{3} {1, 2, 3} {4, 5}
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))
5
6
None
Type Error
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);
7
10
3
8
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);
10 20
20 20
10 10
Error
