Variables & Scope — Test 1
Page 1 of 2
Question 1
What is the output of this Python code?
x = 10
def f():
print(x)
x = 5
f()
FPSC- Programmer (BS-17) - PMD High Yield - 2026
Question 2
What is the output of this C++ code?
int f(){ static int c = 0; return ++c; }
int main(){ f(); f(); cout << f(); }
FPSC- Programmer (BS-17) - Pakistan Meteorological Department (PMD) Model Papers - 2026
Question 3
What is the value of an uninitialized local (automatic) int variable in C++?
FPSC- Programmer (BS-17) - Pakistan Meteorological Department (PMD) Model Papers - 2026
Question 4
What is the value of a global int variable declared without an initializer in C++?
FPSC- Programmer (BS-17) - Pakistan Meteorological Department (PMD) Model Papers - 2026
Question 5
What are the scope and lifetime of a static local variable declared inside a C++ function?
FPSC- Programmer (BS-17) - Pakistan Meteorological Department (PMD) Model Papers - 2026
Question 6
What does this Python code print?
fs = [lambda: i for i in range(3)]
print([f() for f in fs])
FPSC- Programmer (BS-17) - PMD High Yield - 2026
Question 7
Which keyword lets a Python function assign a new value to a module-level variable?
FPSC- Programmer (BS-17) - Pakistan Meteorological Department (PMD) Model Papers - 2026
Question 8
What does this C++ code print?
int x = 1;
{ int x = 2; x++; }
cout << x;
FPSC- Programmer (BS-17) - Pakistan Meteorological Department (PMD) Model Papers - 2026
Question 9
What does this Python code print?
a = [1, 2]
b = a
b.append(3)
print(a)
FPSC- Programmer (BS-17) - Pakistan Meteorological Department (PMD) Model Papers - 2026
Question 10
What does this Python code print?
def f(x, L=[]):
L.append(x)
return L
f(1)
print(f(2))
FPSC- Programmer (BS-17) - PMD High Yield - 2026