Exercises
Explore how functions organize reusable program behavior. This quiz assesses arguments and parameters, return values, local and outer scope, pass-by-value behavior, default parameters, pure functions, shadowing, call stacks, variable lifetime, arity, and function composition. Language-neutral pseudocode keeps the focus on concepts that apply across many programming languages.
Answer the questions below and check the explanation for each answer.
0/11 answered
Auto audio on: the next questions will be read aloud when you click Continue.
A return statement ends the current function call and can provide a result to the calling code.
A parameter is a name in a function declaration. An argument is the value supplied when the function is called.
Lexical scope resolves a name by searching the current scope and then its enclosing scopes. The nearest available declaration is x = 4 in outer.
With pass-by-value, n receives a copy of x's value. Changing n does not change the original variable x, so the program prints 5.
The call stack follows last in, first out. Because gamma was called most recently and is on top, it normally returns first.
A pure function produces the same result for the same inputs and does not alter external state, perform output, or cause other observable side effects.
Shadowing occurs when a declaration in an inner scope uses the same name as one in an outer scope, temporarily hiding the outer declaration.
An omitted optional argument uses its declared default. Therefore, name receives "Mina" and punctuation receives "!".
A standard local variable belongs to a particular function invocation. When that invocation returns and its frame is removed, the local binding is no longer accessible.
The function requires two arguments, but the call supplies only one. Without a default for b, this produces an argument-count or arity error.
The inner call runs first: addOne(3) returns 4. That result becomes the argument to double, which returns 4 × 2 = 8.
Video Courses
Ideal for beginners
Thousands of online courses in video, ebooks and audiobooks.
To test your knowledge during online courses
Generated directly from your cell phone's photo gallery and sent to your email
Download our app via QR Code or the links below:.
+ 10 million
students
Free and Valid
Certificate
60 thousand free
exercises
4.8/5 rating in
app stores
Free courses in
video and ebooks