I'm reteaching myself C++ and as I'm reading about pointers a question has came into mind.
When declaring function signatures in C++, the address-of and dereference operators are used, such as the below.
int someFunction(std::vector& nums) {
//do stuff
}
In this context the &
is being used to declare that the address of the nums
variable is being used rather than the value.
If this signature is changed to the below, the value is being used instead.
int someFunction(std::vector* nums) {
//do stuff
}
However if the below is now used, I assume the value of the nums
variable is still being used despite the lack of operator.
int someFunction(std::vector nums) {
//do stuff
}
If this is true, since the lack of an operator and the *
operator both result in the same thing, why is there any need for the *
operator at all? Is it simply for brevity?
No comments:
Post a Comment