Functions
Function Headers
A function header names the return type, function name, and parameter list.
header
`int square(int value)` is the function header.
definition
The function definition combines the header with the body that runs.
Function Headers
function_prototypes.c
Replay: real traced execution (multi-file project)
#include <stdio.h>
int square(int value) {
return value * value;
}
int main(void) {
int value = 4;
int result = square(value);
printf("square=%d\n", result);
return 0;
}
#include <stdio.h>
int square(int value) {
return value * value;
}
int main(void) {
int value = 6;
int result = square(value);
printf("square=%d\n", result);
return 0;
}
#include <stdio.h>
int square(int value) {
return value * value;
}
int main(void) {
int value = 9;
int result = square(value);
printf("square=%d\n", result);
return 0;
}
value ← 4
7int main(void) {8 int value→ 4 = 4; //@value=6, 99 int result = square(value4);int square(int value)
3int square(int value4) {4 return value4 * value;5}result ← 16
8 int value = 4; //@value=6, 99 int result→ 16 = square(value4);1011 printf("square=%d\n", result16);12 return 0;13}outputsquare=16
value ← 6
7int main(void) {8 int value→ 6 = 6;9 int result = square(value6);int square(int value)
3int square(int value6) {4 return value6 * value;5}result ← 36
8 int value = 6;9 int result→ 36 = square(value6);1011 printf("square=%d\n", result36);12 return 0;13}outputsquare=36
value ← 9
7int main(void) {8 int value→ 9 = 9;9 int result = square(value9);int square(int value)
3int square(int value9) {4 return value9 * value;5}result ← 81
8 int value = 9;9 int result→ 81 = square(value9);1011 printf("square=%d\n", result81);12 return 0;13}outputsquare=81