The return keyword can stop running a function at any time, sending execution back to the statement that called the function.
In the case of the main() function, return exits the program.
The following code uses return to exit a Function.
#include <stdio.h> void display(int stop); int main() //from w w w. j a v a2s . co m { int s; printf("Enter a stopping value (0-100): "); scanf("%d",&s); display(s); return(0); } void display(int stop) { int x; for(x=0;x<=100;x=x+1) { printf("%d ",x); if(x==stop) { puts("You won!"); return; } } puts("I won!"); }