def add_item(item, lst=[ ]):
lst.append(item)
return lst
print(add_item(1))
print(add_item(2))
print(add_item(3, [ ]))
print(add_item(4))
What is the output?
Ctrl+Solve
Quiz
•
Computers
•
University
•
Hard
Muhammed Nihal Noushad
Used 8+ times
FREE Resource
25 questions
Show all answers
1.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
def add_item(item, lst=[ ]):
lst.append(item)
return lst
print(add_item(1))
print(add_item(2))
print(add_item(3, [ ]))
print(add_item(4))
What is the output?
[1] [2] [3] [4]
[1] [1, 2] [3] [1, 2, 4]
[1] [2] [3] [4]
[1] [1, 2] [3] [4]
2.
MULTIPLE CHOICE QUESTION
45 sec • 1 pt
A short snippet is displayed in a scrambled order. Which option shows the correct order for the code?
Scrambled Snippet:
printf("Result: %d", calculate(3));
int calculate(int n) {
return n > 0 ? n * calculate(n - 1) : 1;
}
Expected Output:
Result: 6
int calculate(int n) {
return n > 0 ? n * calculate(n - 1) : 1;
}
printf("Result: %d", calculate(3));
printf("Result: %d", calculate(3));
int calculate(int n) {
return n > 0 ? n * calculate(n - 1) : 1;
}
int calculate(int n);
printf("Result: %d", calculate(3));
int calculate(int n) {
return n > 0 ? n * calculate(n - 1) : 1;
}
int calculate(int n) {
return n > 0 ? n + calculate(n - 1) : 1;
}
printf("Result: %d", calculate(3));
3.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
#include<stdio.h>
void recurse() {
int arr[1000]; // Large stack allocation
recurse();
}
int main() {
recurse();
return 0;
}
What is the error?
No error, infinite recursion allowed
Stack overflow due to uncontrolled recursion
Compilation error due to large array
Undefined behavior
4.
MULTIPLE CHOICE QUESTION
20 sec • 1 pt
x = 0 or None or [ ] or { } or 42
print(x)
What will be printed?
0
None
[ ]
42
Answer explanation
• The or operator returns the first truthy value or the last falsy value if all are falsy.
• 0, None, [], {} are all falsy, so Python keeps evaluating.
• 42 is truthy, so it is returned.
5.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
x = 10
def outer():
x = 5
def inner():
nonlocal x
x += 1
return x
return inner()
print(outer(), x)
What is the output?
6 10
6 6
UnboundLocalError
5 10
6.
MULTIPLE CHOICE QUESTION
45 sec • 1 pt
A short snippet is displayed in a scrambled order. Which option shows the correct order for the code?
Scrambled Snippet:
printf("Value: %d", arr[2]);
arr[2] += modify(arr[1]);
int arr[ ] = {1, 2, 3, 4};
int modify(int x) {
return x * 2;
}
Expected Output:
Value: 7
int modify(int x) {
return x * 2;
}
int arr[ ] = {1, 2, 3, 4};
arr[2] += modify(arr[1]);
printf("Value: %d", arr[2]);
printf("Value: %d", arr[2]);
arr[2] += modify(arr[1]);
int arr[ ] = {1, 2, 3, 4};
int modify(int x) {
return x * 2;
}
int arr[ ] = {1, 2, 3, 4};
arr[2] += modify(arr[1]);
printf("Value: %d", arr[2]);
int modify(int x) {
return x * 2;
}
int modify(int x);
int arr[ ] = {1, 2, 3, 4};
arr[2] += modify(arr[1]);
printf("Value: %d", arr[2]);
int modify(int x) {
return x + 2;
}
7.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
#include<stdio.h>
#include<stdlib.h>
int* createNumber() {
int num = 42;
return #
}
int main() {
int* ptr = createNumber();
printf("%d", *ptr);
return 0;
}
What is the error?
No error, prints 42
Undefined behavior due to returning a local variable's address
Segmentation fault
Compilation error
20 questions
CCE-III Programming in C Language
Quiz
•
University
25 questions
C Quiz 1
Quiz
•
University
25 questions
Aptitude Competition(FY)
Quiz
•
University
20 questions
C Quest 2.0
Quiz
•
University
20 questions
Pointers
Quiz
•
University
20 questions
TECHFEST QUALIFYING ROUND
Quiz
•
University
26 questions
String in C Programming
Quiz
•
University
25 questions
Code Carnival
Quiz
•
University
15 questions
Character Analysis
Quiz
•
4th Grade
17 questions
Chapter 12 - Doing the Right Thing
Quiz
•
9th - 12th Grade
10 questions
American Flag
Quiz
•
1st - 2nd Grade
20 questions
Reading Comprehension
Quiz
•
5th Grade
30 questions
Linear Inequalities
Quiz
•
9th - 12th Grade
20 questions
Types of Credit
Quiz
•
9th - 12th Grade
18 questions
Full S.T.E.A.M. Ahead Summer Academy Pre-Test 24-25
Quiz
•
5th Grade
14 questions
Misplaced and Dangling Modifiers
Quiz
•
6th - 8th Grade