Skip to content

Instantly share code, notes, and snippets.

@drmmr763
Created July 11, 2012 15:49
Show Gist options
  • Save drmmr763/3091291 to your computer and use it in GitHub Desktop.
Save drmmr763/3091291 to your computer and use it in GitHub Desktop.
stuff on functions
/* 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