A function in C can return any type other than an array (excluding array pointers).
Does not specify the return type, in the previous C language version is the default return int, now C99, C + + is not supported.
void means that no return value is required; If the other statement must have a return statement.
In the main function (just the main function) if you forget return, some compilers will automatically add return 0;
1. Each execution return statement function will exit:
#include <stdio.h>
int main(void)
{
printf("111\n");
printf("222\n");
return 0; /* 之后的语句将不会执行 */
printf("333\n");
printf("444\n");
getchar();
return 0;
}
2. If the function does not return a value, you can borrow the returned without parameters:
#include <stdio.h>
void prn(void);
int main(void)
{
prn();
getchar();
return 0;
}
void prn(void) {
printf("111\n");
printf("222\n");
return; /* 无参数的 return */
printf("333\n");
printf("444\n");
}
3. Return is not followed by an "equal sign", but the returned value can also be written in parentheses:
#include <stdio.h>
long long MySqr(int x);
int main(void)
{
int i = 9;
i = MySqr(i);
printf("%d\n", i);
getchar();
return 0;
}
long long MySqr(int x) {
return(x*x); /* 返回值在括号中 */
}