|
|
By Alex, on July 30th, 2007
The use of functions provides many benefits, including:
The code inside the function can be reused. It is much easier to change or update the code in a function (which needs to be done once) than for every in-place instance. Duplicate code is a recipe for disaster. It makes your code easier to read . . . → Read More: 7.5 — Inline functions
By Alex, on July 25th, 2007
There is one more way to pass variables to functions, and that is by address. Passing an argument by address involves passing the address of the argument variable rather than the argument variable itself. Because the argument is an address, the function parameter must be a pointer. The function can then dereference the pointer . . . → Read More: 7.4 — Passing arguments by address
By Alex, on July 24th, 2007
Pass by reference
When passing arguments by value, the only way to return a value back to the caller is via the function’s return value. While this is suitable in many cases, there are a few cases where better options are available. One such case is when writing a function that needs to modify . . . → Read More: 7.3 — Passing arguments by reference
By Alex, on July 23rd, 2007
Pass by value
By default, arguments in C++ are passed by value. When arguments are passed by value, a copy of the argument is passed to the function.
Consider the following snippet:
void foo(int y) { using namespace std; cout << "y = " << y << endl; } int main() { foo(5); // . . . → Read More: 7.2 — Passing arguments by value
By Alex, on July 19th, 2007
The void pointer, also known as the generic pointer, is a special type of pointer that can be pointed at objects of any data type! A void pointer is declared like a normal pointer, using the void keyword as the pointer’s type:
void *pVoid; // pVoid is a void pointer
A void pointer can . . . → Read More: 6.13 — Void pointers
|
|