He doesn't mean like literally return the value, he means it's doing it through pointers.
By the way, what Tvspelsfreak posted is C-style pointers. In C++ you only need &s in the function prototype and don't have to refer to it as a pointer in the function.
Evidently, that's called "passing a reference". I'm pretty against that method as I learned C first so that really confuses the hell outta. Me. I generally stick with my C-whore * pointer references in the functions. I think that might even be more efficient anyway.
Maybe this can help:
&variable = the adress of the variable in memory
variable = the actual variable
*variable = a pointer to the actual variable through the memory adress.
I'll give you the lowdown on printf (seriously this time). XD
the basic structure is like this:
printf("string here.");
Don't forget your \a \n \ts and crap you can do with cout.
Printing variables is a bit different. First, you need a percent sign '%' then you need a letter corresponding to the corect datatype.
d = int
f = float
lf = double
x = hex
Then, you end the string and put a comma followed by the variables in the correct order that you printed them.
that's pretty much all you need to know. I'll give you some examples:
Code: Select all
printf("Here is a float: %f\nHere is an int: %d", float_variable, int_variable);
printf("Lookie, even hex for keyboard goodness: %x\n", key);
cout << "Run this all j00 C++ whores! << endl;
while(1)
printf("\a");
There you have it, the almighty C printf. Printf ownz cout at every application in my opinion and looks neater. Also, it is 100^100 times easier to format text with printf.
I personally prefer printf to cout for all of my text printing needs. ^_^