mirror of
https://github.com/chubin/cheat.sheets
synced 2024-11-19 03:25:44 +00:00
ade78aaafb
This seems to be the predominant choice, and matches the last commit I just made, so I went ahead and converted them all, and changed any, - for example, 2-space indents. Let me know if this is undesired. To understand why I chose to do this, please refer to the previous commit's message.
29 lines
860 B
Plaintext
29 lines
860 B
Plaintext
// ### Functions
|
|
// a simple function
|
|
void functionName() {}
|
|
|
|
// function with parameters of integers
|
|
void functionName(int param1, int param2) {}
|
|
|
|
// return type declaration
|
|
int functionName() {
|
|
return 420;
|
|
}
|
|
|
|
// Return multiple values at once
|
|
// (C++ uses pairs [ 2 values ] and tuple [ more than 2 values ])
|
|
// Please refer pairs and tuple respectively for more information
|
|
std::tuple<double, double> functionName() {
|
|
return std::make_tuple( double1, double2 );
|
|
}
|
|
|
|
pair<double,double> result = functionName();
|
|
std::cout << result.first << std::endl;
|
|
std::cout << result.second << std::endl;
|
|
|
|
// Pass by reference (the caller and the callee use the same variable for the parameter)
|
|
int functionName(int &referenceName) {}
|
|
|
|
// Pass by value (the caller and callee have two independent variables with the same value)
|
|
int functionName(int valueName) {}
|