printf("Start. Give a\n");
scanf("%d",&a);
printf("\na is %d\n",a);
if (a==2)
{
return a;
printf("a is 2\n");
}
return 0;
1.If i put 2 the programm is terminated. Shouldn't it just output the value of a (2)? That happened on C++ I think.
2.And In my book I've red that with return you can restore the cotrol from a function to the main() function. This means that it works like "break;"
-----------------------------------------------------------------------------------------------
My learning process on my blog - http://georgesblogprogramming.blogspot.com/
The return statement exits the current function. If that function happens to be main(), then the program ends.
Take a read through the C++ Language Tutorial for examples, etc. http://www.cplusplus.com/doc/tutorial/
Particularly the Functions (I) and Functions (II) sections.
The return keyword calls the end of a function that has a return value. So if you had a different function that returned the length of a string, for instance, you would not leave that function until you reached a return statement or else some exception occurred and you went out of the functions scope. So when they say that it returns control to the main function it means its then end of the previous function. It does not output the value of two to the screen because that would require a specified output stream and no it does not work like the break keyword.