A function declares its return type, name and parameters. Parameters receive copies of argument values. Returning a result lets the caller decide how to use it. Define the function before calling it, or provide a matching prototype.
Read the example
The complete program appears below. Read it first, predict the output, then run it.
Expected output
Square: 36
Practise
Write a function that accepts two integers and returns the larger one.
Common mistake
A function returning int must return a suitable value on every normal path. Multiplication can overflow for large inputs.
#include <stdio.h>
int square(int value) {
return value * value;
}
int main(void) {
int result = square(6);
printf("Square: %d\n", result);
return 0;
}
PRACTICE LAB
Read. Edit. Run.
C source · .c
Experiment with the program below. Your code and input are sent to the selected compiler only when you run it.
Tab indents · Shift+Tab unindents · Esc then Tab leaves the editor · Ctrl/Cmd+Enter runs · Ctrl/Cmd+S saves a draft
Changes save automatically to your account.
Input / output example
Example input
No input required.
Expected output for the original program
Square: 36
Output will appear here.
Debugging Lab
Interactive Memory Visualizer
Educational simulation — addresses and execution steps are illustrative.