Created
July 11, 2012 15:49
-
-
Save drmmr763/3091291 to your computer and use it in GitHub Desktop.
stuff on functions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* So here's the skinny on void & returns: | |
All functions, like double or int, should return _something_. That's why you use the return line. | |
The only time a function DOESN"T return a value, is when you use void. Void means the function does something, but doesn't return a value. | |
So for example you could have two functions: */ | |
// simple main function. just uses two other functions to do everything | |
int main() { | |
// call the print function and pass it the add function as a parameter | |
print(add(2, 4)); | |
system pause; | |
return 0; | |
} | |
// simple function to add values. MUST have a return | |
double add(int a, int b) { | |
return (a + b) | |
} | |
// a void function doesn't need to return anything, it JUST prints. | |
void print(int sum) { | |
cout sum; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment