Ctrl+Solve

Ctrl+Solve

University

25 Qs

quiz-placeholder

Similar activities

Unit-2 Test-1

Unit-2 Test-1

University

20 Qs

C-Py QUIZ | ROUND 1

C-Py QUIZ | ROUND 1

University

20 Qs

OCS752_CP_WEEKLY_TEST3 (20.08.2020)

OCS752_CP_WEEKLY_TEST3 (20.08.2020)

University

20 Qs

Array Addresses 2024

Array Addresses 2024

University

20 Qs

Conocimientos básicos de C

Conocimientos básicos de C

University

20 Qs

Bridge course with C

Bridge course with C

University

20 Qs

Pointers in C

Pointers in C

University

24 Qs

C Programming Quiz

C Programming Quiz

12th Grade - University

20 Qs

Ctrl+Solve

Ctrl+Solve

Assessment

Quiz

Computers

University

Hard

Created by

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 &num;

}

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

Create a free account and access millions of resources

Create resources
Host any resource
Get auto-graded reports
or continue with
Microsoft
Apple
Others
By signing up, you agree to our Terms of Service & Privacy Policy
Already have an account?