Course contentsShow
← Computer Science
Lesson 188 of 2,8725. Functions and ModularityFree lesson

Calling Functions

Understanding how to invoke functions and pass control from caller to callee.

Calling Functions

What you'll learn: How to actually use a function you've declared by invoking it and passing control to its code.

The Core Idea

You've learned what functions are and how to declare them—now it's time to call (or "invoke") them. Calling a function means telling your program to stop what it's doing, jump to the function's code, execute that code, and then come back to where you left off.

Think of it like asking a friend for help: you call out their name, they come over and do their task, then you continue with your work. The function call is you "calling out," and the function definition is your friend's response.

How It Works

When you call a function, you write its name followed by parentheses. If the function expects information (called parameters, which we'll cover soon), you'd include that inside the parentheses—but even if it needs nothing, the parentheses are required.

# Assuming we've already declared a function named greet
greet()  # This is a function call

The moment your program reaches this line, control transfers to the greet function. The computer executes every line inside greet, then returns control to the line right after the call.

Caller and Callee

  • Caller: The code that invokes the function
  • Callee: The function being called

The caller temporarily pauses, the callee runs, then the caller resumes.

Key Takeaway: Calling a function transfers control from the caller to the function's code using the function name followed by parentheses, then returns control when the function completes.