What is the difference between passing a pointer* of an object to a function; and passing &object to a function?
What is the difference between passing a pointer* of an object to a function; and passing &object to a function?
Passing a plain pointer to the function allows the function to alter the pointer's value.
Passing &pointer to a function tells the function it's not alloud to change the value of the pointer, only use it's current value.
Code:Error W8057 C:\\Life.cpp: Invalid number of arguments in function run(Brain *)
& is either a reference or the operator that returns the memory address of a variable.
A reference is basically a pointer that can only point to a single object (but you can modify the object that it points to).
You can use a pointer to allocate memory.
I'm not immature, I'm refined in the opposite direction.
So can I change the contents of the struct object with * or &? Also, in the function definition, the object will be defined with its class name or struct name?
eg
myString* myclass ::function(myString &string1)
or
myString* myclass ::function(myclass &string1)
a reference (type&) cannot be rebound to another location in memory. a pointer (type*) can. also to change the value stored at the location in memory of a pointer, you must dereference it (*pointerVariableName = value). this is not necessary with a reference. neither the value at nor the location of a const reference may be changed.
So, basically you are asking about the difference between passing an object by reference and passing a pointer to it by value?So can I change the contents of the struct object with * or &?
Eh, what do you mean? myString is one type name, myclass is another type name, and they have nothing to do with each other unless one is an alias (due to typedef) of the another or both are aliases of another type name.Also, in the function definition, the object will be defined with its class name or struct name?
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)