Questions: Variable Scope

5 questions to test your understanding

Score: 0 / 5
Question 1 Multiple Choice

A function contains the line count = 0. There is also a global variable named count with a value of 10. After calling the function, what is the value of the global count?

A0, because the function's assignment overwrites the global
B10, because the function creates its own local count that is completely independent of the global
CAn error is raised because count is already defined globally
DUndefined, because the function destroys the global when it creates a local with the same name
Question 2 Multiple Choice

The same function is called twice in a row: process(5) then process(10). What is true about the local variables inside process()?

ABoth calls share the same local variables, so the second call can see values left by the first
BEach call gets its own fresh, independent set of local variables
CThe second call inherits the local variable values from the first call
DLocal variables are only created on the first call; subsequent calls reuse them
Question 3 True / False

A local variable x defined inside function_a and a local variable x defined inside function_b refer to the same memory location.

TTrue
FFalse
Question 4 True / False

A function that reads and modifies a global variable is harder to debug than a function that only uses parameters and return values.

TTrue
FFalse
Question 5 Short Answer

Why does limiting variable scope — keeping variables as local as possible — make programs easier to debug and reason about?

Think about your answer, then reveal below.