ConceptStep · learning platform for computer science

Parameters and return

C programming · Lesson

C · lesson 13 / 27

Parameters and return

Follow arguments entering parameters and a value returning to main.

1 · Observe and predict

The concept

Parameters are local variables initialized from argument values; return ends the function and sends a value to the caller.

Mental model:

x,y → massimo(a,b) → choose a/b → return → m

2 · Algorithm view

Observe the equivalent algorithm

For functions the flowchart shows the algorithmic effect. The Call Stack Explorer below shows what really happens between main, parameters, frames and return.

Loading flowchart…
3 · Call Stack Explorer

Follow the call frame by frame

Move through the steps: frames show which variables exist at that moment and the source highlights the involved lines.

1 / 4

main reads x and y

The values that will be passed are 8 and 5.

main
x8 y5
4 · Flowchart ↔ C · Run in Page

Lab 1 — Run the example program

Run C executes only the example shown on the left, using stdin on the right. The coding challenge below has a separate editor and test button.

Parameters and return Start the flowchart to synchronize the code
                        1#include <stdio.h>
                        2 
                        3int massimo(int a, int b)
                        4{
                        5    if (a > b)
                        6    {
                        7        return a;
                        8    }
                        9    return b;
                        10}
                        11 
                        12int main(void)
                        13{
                        14    int x;
                        15    int y;
                        16    scanf("%d", &x);
                        17    scanf("%d", &y);
                        18    int m = massimo(x, y);
                        19    printf("%d\n", m);
                        20    return 0;
                        21}
Ready. Make a prediction before running.

                    
                

Lab 2 — Coding challenge: write your code — Maximum function

Implement massimo(int a,int b), read two integers and print the larger.

This is a different program from lab 1. Complete the starter code: Check all test cases compiles this editor and tests every input, including boundary cases.

5 · Guided practice

Check your prediction

If massimo receives 8 and 5, which return executes?

Challenge 1 / 5 · Understanding

Progress: 0 / 5 · correct: 0

Your competency map

What you need to know for Parameters and return

ConceptStep separates what is required from what is recommended or useful as reinforcement. Only required prerequisites block your progress.

Current topic Strong skill Review due Needs reinforcement To be mastered Optional support

Relationships: solid line = required · dashed line = recommended · dotted line = reinforcement.

GUIDED LEARNING PATHS

Want to choose the next skill to develop?