A question about preference in C functions...
Are there any benefits/downsides to passing an argument as a pointer to a function as opposed to passing the variable?
For example: void doSomething(int x); vs void doSomething(int *x); |
it is simply different,
passing a pointer means no copy of data, and when doSomething changes x the caller has the new value passing by value means that doSomething has a fresh and own copy of the passed data |
I see now, great thanks.
|
I would add that, as a rule of thumb, if you want to pass a large object, such as a struct, to the function, it is much faster to just pass the pointer. If you want to pass a large object, but don't want that object changed by the function, or want to make it explicitly clear that the function will not change the object, use a const pointer.
|
Awesome thanks.
|
All times are GMT -5. The time now is 01:43 AM. |