`return` — C Keyword
`return` — C Keyword
The return keyword in C: exits the current function, optionally returning a value.
`return` — C Keyword
The return keyword in C: exits the current function, optionally returning a value.
Use reference pages to confirm names, categories, nearby facilities, and the constraints that matter before writing or reviewing code.
return (C)Exits the current function. An expression may follow return to provide the return value; void functions use bare return or fall off the end.
return; /* void function */
return expression; /* returns a value */
#include <stdio.h>
int add(int a, int b) {
return a + b;
}
int abs_val(int n) {
if (n < 0) return -n;
return n;
}
int main(void) {
printf("%d\n", add(3, 4)); /* 7 */
printf("%d\n", abs_val(-5)); /* 5 */
return 0;
}
main with no return returns 0 (C99+).void function without a return is undefined behavior.returnint main() {
// Pick one facility from this reference page.
// Write the smallest program that exercises its main precondition,
// complexity rule, or lifetime constraint before scaling up.
return 0;
}