main reads x and y
The values that will be passed are 8 and 5.
x8
y5
C programming · Lesson
Follow arguments entering parameters and a value returning to main.
Parameters are local variables initialized from argument values; return ends the function and sends a value to the caller.
x,y → massimo(a,b) → choose a/b → return → m
For functions the flowchart shows the algorithmic effect. The Call Stack Explorer below shows what really happens between main, parameters, frames and return.
Move through the steps: frames show which variables exist at that moment and the source highlights the involved lines.
The values that will be passed are 8 and 5.
x8
y5
a and b are local variables of massimo.
a8
b5
x8
y5
Because a > b is true, return a is executed.
a8
b5
x8
y5
The massimo frame disappears; m keeps the returned value.
x8
y5
m8
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.
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}
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.
If massimo receives 8 and 5, which return executes?
Challenge 1 / 5 · Understanding
Progress: 0 / 5 · correct: 0
ConceptStep separates what is required from what is recommended or useful as reinforcement. Only required prerequisites block your progress.
Relationships: solid line = required · dashed line = recommended · dotted line = reinforcement.