wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

BugBlitz

Total questions: 15

Worksheet time: 15mins

Name
Class
Date
1.

Q1: What is the output?

(Pointer Arithmetic & Undefined Behavior)

c

#include <stdio.h>

int main()

{ int arr[] = {10, 20, 30};

int *p = arr;

printf("%d", p++ + ++*p);

return 0; }

a)

21

b)

31

c)

Undefined Behaviour

d)

Compilation Error

2.

Q2: What does this code print?

(Function Pointers & Recursion)

c

#include <stdio.h>

int (*func(int x))(int) {

return x > 0 ? func : NULL; }

int main() {

printf("%p", func(5)(0));

return 0; }

a)

0

b)

segmentation fault

c)

Address of func

d)

Compilation Error

3.

Q3: What is the output? (Templates & SFINAE)

cpp

#include <iostream>

template auto foo(T x) -> decltype(x + 1)

{ return x + 1;

} int main()

{ std::cout << foo("hello");

return 0; }

a)

hello1

b)

Compilation Error

c)

Undefined Behavior

d)

Runtime Error

4.

Q4: What does this code output? (Lambda & Capture Semantics)

cpp

#include <iostream>

int main() {

int x = 10;

auto f = [&x]() mutable { x = 20; };

f(); std::cout << x; return 0; };

a)

10

b)

20

c)

Comilation Error

d)

Undefined Behavior

5.

Q5: What is the output? (Metaclasses & Inheritance)

python

class Meta(type):

def new(cls, name, bases, dct):

dct['x'] = 100

return super()._new_(cls, name, bases, dct)

class A(metaclass=Meta):

pass

print(A.x)

a)

100

b)

AttributrError

c)

TypeError

d)

0

6.

Q6: What does this code print? (Generator Coroutines)

python

def gen():

yield (yield (yield 1))

g = gen()

print(next(g))

print(g.send(2))

print(g.send(3))

a)

1 2 3

b)

1 3 stopiteration

c)

1 2 stopiteration

d)

TypeError

7.

Q7: What happens with this CSS Grid? (Subgrid & Alignment)

css

.container {

display: grid;

grid-template-columns: subgrid;

gap: 10px;

}

.item {

grid-column: span 2; }

a)

Items span 2 columns in a subgrid

b)

subgrid is invalid

c)

Items stack vertically

d)

Overlapping items

8.

Q8: What does this HTML + Shadow DOM code do?

javascript

const div = document.createElement('div');

const shadow = div.attachShadow({ mode: 'closed' });

shadow.innerHTML = <style>p {color; red; } <style><p>Hello</p>

; document.body.appendChild(div);

console.log(shadow.querySelector('p'));

a)

Logs <p>

element

b)

Logs null

c)

Throws TypeError

d)

Logs undefined

9.

Q9: What is the output? (Promise Chaining & Microtasks)

javascript

Promise.resolve()

.then(() => console.log(1))

.then(() => {

Promise.resolve().then(() => console.log(2)); }) ;

.then(() => console.log(3));

a)

1 2 3

b)

1 3 2

c)

2 1 3

d)

3 2 1

10.

Q10: What does this Proxy code log? (Reflect API & Traps)

javascript

const obj = { x: 10 };

const proxy = new Proxy(obj, {

get(target, prop) {

return Reflect.get(target, prop) * 2;

}

});

console.log(proxy.x + obj.x);

a)

20

b)

10

c)

30

d)

TypeError

11.

Q11: What is the output? (Python + C Integration)

python

from ctypes import *

lib = CDLL("libc.so.6")

printf = lib.printf

printf(b"Hello, %s\n", b"World")

a)

Hello, world

b)

Segmentation Fault

c)

TypeError

d)

None

12.

Q12: What does this C++/Python hybrid code do? (Pybind11 Example)

cpp

#include<pybind11/pybind11.h>

PYBIND11_MODULE(example, m)

{ m.def("add", [](int a, int b) { return a + b; });

}

a)

Exposes a python module with an add() function

b)

Compilation Error

c)

Runtime crash

d)

Nothing

13.

Q13: What is the output of this C code?

c

#include<stdio.h>

int main() {

int x = 5; printf("%d", x++ + ++x);

return 0;

}

a)

10

b)

20

c)

50

d)

Undefined Behavior

14.

Q14: What does this C code print?

c

#include<stdio.h>

#define SQUARE(x) (x * x)

int main() {

printf("%d", SQUARE(2 + 3));

return 0; }

a)

25

b)

13

c)

11

d)

5

15.

Q15: What is the output of this JavaScript code? (Async/Await & Error Handling)

javascript

async function test() {

throw new Error('Oops!');

}

test().catch(e => console.log(e.message));

a)

Oops!

b)

TypeError

c)

undefined

d)

Promise rejected