NEW
Font size
WorksheetsBugBlitz
Total questions: 15
Worksheet time: 15mins
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; }
21
31
Undefined Behaviour
Compilation Error
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; }
0
segmentation fault
Address of func
Compilation Error
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; }
hello1
Compilation Error
Undefined Behavior
Runtime Error
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; };
10
20
Comilation Error
Undefined Behavior
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)
100
AttributrError
TypeError
0
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))
1 2 3
1 3 stopiteration
1 2 stopiteration
TypeError
Q7: What happens with this CSS Grid? (Subgrid & Alignment)
css
.container {
display: grid;
grid-template-columns: subgrid;
gap: 10px;
}
.item {
grid-column: span 2; }
Items span 2 columns in a subgrid
subgrid is invalid
Items stack vertically
Overlapping items
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'));
Logs <p>
element
Logs null
Throws TypeError
Logs undefined
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));
1 2 3
1 3 2
2 1 3
3 2 1
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);
20
10
30
TypeError
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")
Hello, world
Segmentation Fault
TypeError
None
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; });
}
Exposes a python module with an add() function
Compilation Error
Runtime crash
Nothing
Q13: What is the output of this C code?
c
#include<stdio.h>
int main() {
int x = 5; printf("%d", x++ + ++x);
return 0;
}
10
20
50
Undefined Behavior
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; }
25
13
11
5
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));
Oops!
TypeError
undefined
Promise rejected
