Let's consider the following toy project:
#include <stdio.h>
int Compare(int a, int b)
{
return a - b;
}
void PrintComparison(int a, int b)
{
int result = Compare(a, b);
if (result < 0)
{
printf("%d is less than %d.\n", a, b);
return;
}
if (result > 0)
{
printf("%d is larger than %d.\n", a, b);
return;
}
// result == 0
printf("%d is equal to %d.\n", a, b);
}
int main()
{
PrintComparison(1, 2);
PrintComparison(4, 3);
PrintComparison(5, 5);
return 0;
}
When you have a function, it must have a return value. It could be anything, such as an integral number, a floating point number, a string, a pointer, even structures defined by you, or nothing (void). This allows the function to communicate back some kind of result to the called.
In the first function, int Compare(int a, int b), we calculate the difference between two integral numbers and return the result: return a - b. Later on, this returned value is stored: int result = Compare(a, b);
In the second function, void PrintComparison(int a, int b), we have a void return value, so this function will not return anything to the caller. In this function, we print to the standard output what we get back from Compare. You can still call return in this function if you want to exit the function, but no value must be specified. You can see such calls when we check whether result is less or larger than 0.
I hope this clears things up. Good luck!