Exercises

Function Calls, Parameters, and Variable Scope

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

  1. 1

    What is the primary purpose of a return statement in a function?

  2. 2

    In the call calculate(12), the function is declared as calculate(amount). Which statement is correct?

  3. 3

    In the illustrated nested functions, which value does inner print under lexical scope?

    Question 3
  4. 4

    Assume primitive numbers are passed by value. What is printed by this pseudocode: x = 5; function bump(n) { n = n + 1 }; bump(x); print(x)?

  5. 5

    The illustrated call stack shows alpha calling beta, which calls gamma. Which function normally finishes and returns first?

    Question 5
  6. 6

    Which description best defines a pure function?

  7. 7

    The diagram shows an inner scope declaring count even though an outer scope already has a variable named count. What is this called?

    Question 7
  8. 8

    A function is declared as greet(name, punctuation = "!"). What happens when greet("Mina") is called?

  9. 9

    The illustration shows a function's stack frame being removed after the function returns. What normally happens to its local variable temp?

    Question 9
  10. 10

    A function combine(a, b) requires two parameters and defines no defaults. What normally happens when it is called as combine(5)?

  11. 11

    The diagram represents double(addOne(3)), where addOne(n) returns n + 1 and double(n) returns n × 2. What is the final result?

    Question 11

Download the App now to have access to + 5000 free courses, exercises, certificates and lots of content without paying anything!

  • 100% free online courses from start to finish

    Thousands of online courses in video, ebooks and audiobooks.

  • More than 60 thousand free exercises

    To test your knowledge during online courses

  • Valid free Digital Certificate with QR Code

    Generated directly from your cell phone's photo gallery and sent to your email

Cursa app on the ebook screen, the video course screen and the course exercises screen, plus the course completion certificate