answersLogoWhite

0


Best Answer

When an object is passed to a function by pointer, a copy of the pointer's value is passed to the function. Pointers are always passed by value, but because the value is a memory address than can be dereferenced, they enable us to pass objects by reference. In languages such as C which have no concept of references, this was the only way to pass by reference. C++ introduced proper references (aliases for existing objects), thus when we want to pass by reference we can choose to use a pointer or an actual reference. Normally we'd only pass by pointer when passing an optional argument that defaults to NULL when no argument is given. Otherwise we pass by reference because references can never be NULL.

User Avatar

Wiki User

9y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

12y ago

Like any other parameter:

char *p;

myfun (p);

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is actually passed to a function when an object is passed to a function through a pointer?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

What is an address in C plus plus programming?

An address in C or C++ is the location in memory of an object or function. An address is the contents of a pointer, as opposed to the contents of the memory location pointed to by the pointer.


Why you can not use this pointer in static functions?

Because this points to the current object, but static methods don't have a current object (actually this is definition of the static methods).


When you let your pointer linger over an object the pointer is?

The pointer is non-NULL.


How do you pass the address of the object as function argument in c plus plus?

Use the address-of operator (&). Note that the function must accept a pointer to the class type. If it accepts a reference or value then you cannot pass the object's address, you must pass the object itself.


Different types of pointers in c language?

... are usable. void pointer (generic pointer) : a special type of pointer which point to some data of no specific types. void *p; null pointer : a special type of pointer which point nowhere. it is usually used to check if a pointer is pointing to a null or free the pointer during deallocation of memory in dynamic memory allocation; it is define by using the predefine constant NULL int *p=NULL; wild pointer : uninitialized pointer. it hold a garbage value. i.e it is not pointing to any memory location yet. dangling pointer: pointer pointing to a destroyed variable. it usually happen during dynamic memory allocation when the object is destroyed but not free and the pointer is still pointing to the destroy object.

Related questions

What is dangling pointer reference in c plus plus?

A dangling pointer (we also use the terms stray pointer and wild pointer) is created whenever we call delete on a pointer and then try to use the pointer without reassigning it.We can also create dangling pointers inadvertently by calling a rogue function that returns a pointer to an object that is local to the function we are calling. The object will fall from scope when the function returns so the pointer is left dangling.Note that there is no such thing as a dangling pointer reference. Pointers and references are not the same. A reference is merely an alias to an object -- it consumes no memory beyond the object it refers to. Whereas a pointer is a variable that may contain the address of an object, but it requires additional memory to do so (4 bytes on 32-bit architecture). Pointers may be NULL, references can never be NULL. Pointers to valid objects require indirection, references do not. References are the preferred method of accessing an object's members, not least because they are easier to work with.


If object 1 call object 2 in oop in which object the excution happen?

Strictly speaking, neither. Although member functions are obviously members of an object, this is merely an abstraction. In reality, there is only one instance of every member function, not one per object. The function knows which instance it was invoked against through the implicit 'this' pointer that is passed to the function through a hidden parameter. Thus execution occurs within the function that was invoked, not within the objects itself.


Why do you use double star '' in initializing a variable in class?

The double star (**) notation is not specific to initializing a variable in a class. It is simply a double indirect reference to an object.float myFloat; // an objectfloat *myFloatPtr; // a pointer to an objectfloat **myFloatPtrPtr; // a pointer to a pointer to an objectmyFloat = 123.456; // initialize an objectmyFloatPtr = &myFloat; // initialize a pointer to an objectmyFloatPtrPtr = myFloatPtr; // initialize a pointer to a pointer to an objectmyFloat; // refer to an object*myFloatPtr; // refer to an object through a pointer**myFloatPtrPtr; // refer to an object through a pointer to a pointer*myFloatPtrPtr; // refer to the value of the pointer to the objectDouble pointer notation is used where the caller intends that one of its own pointers need to be modified by a function call, so the address of the pointer, instead of the address of the object, is passed to the function.An example might be the use of a linked list. The caller maintains a pointer to the first node. The caller invokes functions to search, add, and remove. If those operations involve adding or deleting the first node, then the caller's pointer has to change, not the .next pointer in any of the nodes, and you need the address of the pointer to do that.


How this pointer works in C plus plus?

The "this" pointer is a pointer to the instance of the object, with scope within a member function of that object. It is not always necessary to use it, as references to variables defined in the object will be implicitly prefixed with "this->", but it can resolve name scoping problems, and it can make the code more readable.


How function pointer is represented?

A pointer's type does not affect how an address is represented, it affects how the object at that address is to be interpreted. As such, function pointers are represented no differently to any other type of pointer. If the system uses 32-bit addressing than a pointer is 32-bit variable regardless of the type it refers to.


What is diffrent between object pointer and this pointer?

'this' is an object-pointer: it points to the current object (usable only in non-static methods).


What is an address in C plus plus programming?

An address in C or C++ is the location in memory of an object or function. An address is the contents of a pointer, as opposed to the contents of the memory location pointed to by the pointer.


Why you can not use this pointer in static functions?

Because this points to the current object, but static methods don't have a current object (actually this is definition of the static methods).


When you let your pointer linger over an object the pointer is?

The pointer is non-NULL.


Why pointer is not an object?

A pointer in itself is not an object, because it is not an instance of a class. Of course you can define a class which has only one member, which is a pointer. class Pointer { public void *ptr; }; Pointer p, q, r;


How do you pass the address of the object as function argument in c plus plus?

Use the address-of operator (&). Note that the function must accept a pointer to the class type. If it accepts a reference or value then you cannot pass the object's address, you must pass the object itself.


Different types of pointers in c language?

... are usable. void pointer (generic pointer) : a special type of pointer which point to some data of no specific types. void *p; null pointer : a special type of pointer which point nowhere. it is usually used to check if a pointer is pointing to a null or free the pointer during deallocation of memory in dynamic memory allocation; it is define by using the predefine constant NULL int *p=NULL; wild pointer : uninitialized pointer. it hold a garbage value. i.e it is not pointing to any memory location yet. dangling pointer: pointer pointing to a destroyed variable. it usually happen during dynamic memory allocation when the object is destroyed but not free and the pointer is still pointing to the destroy object.