The return statement "returns" control to the function that invoked the function executing the return statement. Adding a value, such as return 0, adds a "return value", which the invoking function can inspect. The type of the returned value is declared along with the function's declaration, such as int myfunction(...) - it can be any type, not just an int.
If the "invoking function" is the operating system, the return statement returns control back to the operating system. The value of the return, in this case an int, tells the operating system what the result of the execution of the entire program was.
By convention, but this is operating system, shell, and/or programmer determined, a return value of 0 normally means "success", while anything else means "some kind of error", and the actual value identifies what kind of error.
It literally means -48. We use this convention whenever we want to convert a character or string representing a whole number to an actual number.
The character '0' is actually represented by the ASCII character code 48 decimal, or 0x30 in hexadecimal. Thus the following declarations are effectively the same:
char chr = '0';
char dec = 48;
char hex = 0x30;
In the ASCII character set, the characters '0' through '9' have character codes 48 through 57 decimal (0x30 through 0x39 hexadecimal). This is quite convenient as it allows us to convert these character codes to their actual digits, simply by subtracting 48 from the character code.
char nine = '9'; // nine = 57
nine = nine - 48; // nine = 9
Rather than trying to remember the number 48, it's more convenient to use the character code indirectly, via the constant literal '0'. The compiler takes care of the conversion for us, so there's no loss in performance whichever way you do it.
char eight = '8'; // eight = 56
eight = eight - '0'; // eight = 8
Of course C/C++ has a built-in subtract and assign operator, so you will typically see this type of conversion written as follows:
char seven = '7'; // seven = 55
seven -= '0'; // seven = 7
Once we can convert an individual numeric character to its equivalent numeric value, it's fairly simple to convert a string of digits to an integer. All we have to do is multiply each digit by an increasing power of 10, from the right, and add them all together.
char * str = "12345";
int number = 0;
int power = 1; // the right-most column is 10^0, which is 0, but we can't multiply by 0, so we start with 1.
int len = 5
while(len--)
{
number += ( str[i] - '0' ) * power;
power *= 10; // increase the power by 10.
}
printf( "%d", number );
Output: 12345
#include<windows.h> int main() { MessageBox(0,"Hello","Welcome Message",1); return 0; }
The return value tells you if any errors occurred. A value of 0 typically indicates no error.
#include int main (void){char new [3] = "NEW";printf ("new='%.3s'\n", new);return 0;}in C++:int main (void){char newstr [4] = "NEW";printf ("new='%.3s'\n", newstr);return 0;}
int GetMaxElement( void * array) { if (array != 0) { return(max(array[], typeof(array))); } return(0); }
Address of the allocated area, or NULL.
int main (void) { puts ("Hello, world"); return 0; }
#include<windows.h> int main() { MessageBox(0,"Hello","Welcome Message",1); return 0; }
The return value tells you if any errors occurred. A value of 0 typically indicates no error.
For example: int main (void) { return 0; }
c + 0 = c
#include int main (int argc, char **argv){int i;for (i=0; i
#include <iostream> int main() { std::cout << "a plus bi" << std::endl; return 0; }
#include <iostream> using standard namespace std; int main() { cout << "your prob shouldn't be taking c++"; return 0; }
#include<iostream> int main() { std::cout << "Hello world!" << std::endl; return(0); }
A=0 b=0 c=0
#include<iostream> int main() { for(int i=0; i<=12; ++i ) std::cout<<"7 x "<<i<<" = "<<7*i<<std::endl; return(0); }
#include int main (void){char new [3] = "NEW";printf ("new='%.3s'\n", new);return 0;}in C++:int main (void){char newstr [4] = "NEW";printf ("new='%.3s'\n", newstr);return 0;}