Best Answer


void foo( MyClass& object ){} // function with call by reference signature

MyClass* p = new MyClass(); // instantiate a pointer to MyClass

foo( *p ); // call by reference using the pointer

User Avatar

Wiki User

โˆ™ 2013-02-11 05:20:18
This answer is:
User Avatar
Study guides
See all Study Guides
Create a Study Guide

Add your answer:

Earn +20 pts
Q: Call by reference using pointer in c plus plus?
Write your answer...
Related questions

What is a reference variable in c plus plus?

A reference variable in C++ is a formal parameter of a function call that automatically dereferences itself, as if it were a pointer, into a reference to the original value in the calling routine. You declare the reference type in the function declaration and prototype, but the compiler automatically adds the reference (&) operator on call, and the dereference (*) operator on use.

Why pointer is used to reference a string of characters write C plus plus statements that display the text hello using pointer to a string notation?

We use a pointer to reference a string because a string is an array of characters where every element is a char (or a wchar_t if using UNICODE strings). Passing arrays by value would require the entire array to be copied, but passing a pointer variable to an array only copies the pointer, which is effectively the same as passing the array by reference. #include <iostream> int main() { char * psz = "hello"; // pointer to a null-terminated string. std::cout << psz; // pass the pointer (by value) to the insertion operator. return( 0 ); }

What is the difference between Typedef and Reference in C plus plus?

A typedef is a compiler macro. A reference is a pointer, usually implemented with transparent syntax. They have no relationship between each other.

When you call new will it internally call delete in c plus plus?

No. Calling new returns a pointer to allocated memory. If you re-use a pointer to store the return value, then you must release the memory that it previously pointed at, either by deleting the pointer, or by maintaining a separate pointer to the original memory. Calling new will not release the current memory for you.

What is Dazzling Pointer in c plus plus?

The pointer that points to a block of memory that does not exist is called a dazzling pointer or wild pointer

What does c plus plus use call by value or call by reference?

C++ uses call by value. Even you you use call by reference semantics, it is still call by value - the value you are passing in that case is simply the address of the argument.

What is meant by generic pointer in c plus plus?

generic pointer is a pointer that can not be dereferenced i.e one type pointer can not be assigned to another type.

In c plus plus accessing members from objects?

To access members of an object, use the member-of operator. If using a pointer to an object, use the pointer-to-member operator instead. The following minimal example demonstrates both operators: struct foo { int data; }; int main() { foo f; // static reference foo* p = &f; // pointer to reference; // assign by using member-of operator p->data=0; // assign by using pointer-to-member operator }

How do you use call by reference in c plus plus?

Call by reference means calling a function using a reference to a variable or a pointer. You call a function by passing refrences to a variable. For eg: void x(int &a) { a=2; } void main() { int s=3; x(s); } OR void a(int &c) { c=5;}void main(){ int *p; *p=2a(*p);}

How do you update a data file in c plus plus with a reference?

You cannot store references. A reference is nothing more than an alias, an alternate name for an existing variable or constant. References are primarily used when passing variables to functions such that the function can operate upon the variable itself -- known as passing by reference. The function refers to the variable by a different name, an alias, but it is the same variable. By contrast, when passing a variable by value the function uses a copy of that variable, assigning the variable's value to that copy. References are often confused with pointers, primarily because C uses the term to mean a pointer (hence the term, dereferencing). But in C++ a reference is a separate entity altogether. Unlike a reference, a pointer is a variable in its own right, one that can be used to store a memory address. Since a pointer has storage, you can store a pointer in a data file. However, in reality you are only storing the pointer's value -- a memory address -- not an actual pointer. Pointers and references are similar insofar as they can both refer to an object. A pointer does this by storing the memory address of the object, while a reference refers directly to the object itself. Thus if you have a pointer and a reference to the same object, the pointer's value is exactly the same as the address of the reference. Therefore the only way you can store a reference is by storing the object being referred to, not the reference itself.

What is an alias name given to a variable in opp with c plus plus?

An alias is a reference, an alternate name for a variable or constant. You can assign the address of any variable or constant to a reference of the same type. A reference is a bit like a constant pointer to the type but, unlike a pointer, a reference has no address of its own thus you cannot store references. More importantly, references can never be NULL. They are simply an alternative name by which you can refer to an existing variable or constant. When you assign a value to an existing reference to a variable, you are assigning the value to the variable itself. When you pass a reference to a function, you are passing the address of the value being referred to, and that address is assigned to the function's reference argument and is local to the function. This is not unlike passing a pointer, but pointers may be NULL, references are guaranteed to be non-NULL (a NULL reference invalidates your program). Note that C++ references are not the same as C reference variables or constants. In C, a reference variable is simply a non-const pointer, while a reference constant is a constant pointer. Hence pointers can be dereferenced (both in C and C++). But in C++, a reference is neither a variable nor a pointer, but is constant (it always refers to the same object and cannot be reassigned once assigned).

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.

What is uninitialized pointer in c plus plus?

An uninitialized pointer is the same as any other uninitialized variable. It has no definite value. Using (or dereferencing) an uninitialized pointer can result in bad results or damage to some unknown area of the program, data, or operating system, or it can result in a bus fault.

What is a reference in C plus plus?

A reference is an alias for a variable. Unlike a pointer variable, which must occupy memory in order to store the memory address of the object it points to, a reference consumes no memory other than that used by the object it references. An array name is a typical example of a reference. It is an alias to the memory allocated to the array.

What is a call by reference?

In C++ (C Plus Plus), when you call by reference, you are directly accessing the data of the referenced object. When you pass an object to a function by reference, any and all alterations to the object made within the function carry through to the actual object.

What is mean by pointer in c plus plus?

A pointer is an object that contains the address of another object, hence the term pointer, meaning that one object points to another.

How do you access memory dynamically in c plus plus?

You access memory with a pointer or a reference to the memory. To allocate memory dynamically, use calloc or malloc (C or C++) or new (C++ only).

What is meant by pointer in c plus plus?

A pointer is an object that refers to another object. It contains the address of another object. Using dereference syntax (*) you can treat a pointer as an identifier to the object that it points to. Also, you can implicitly treat pointers and arrays in a similar fashion, because array syntax is simply a means of adding an offset to the value of a pointer, before accessing the object to which it points.

What is 'this' pointer in c plus plus?

Address of the current object.

What is the importance ampersand in c plus plus language?

The ampersand '&' has many uses in the C++ language:The single ampersand can be used to reference the pointer address of a pointer:int* pointer;int* anpointer;anpointer = &pointer;This example, although perhaps not valid, shows that the anpointer reference is now the same as the reference to the pointer memory address.The single ampersand can also be used to reference an object in a function:void function( int param1, int param2, int &reference );If this function were to be called, and the reference object altered within the function, the actualy object that was passed into the function would be altered.The double ampersand '&&' specifies that the left AND the right concepts must both be true before the whole statement is true. For example:if( conceptA true ){conceptC = true;}

What disadvantages of using pointers in c plus plus language?

There are no disadvantages of using pointers in C or C++. There are only poor programmers that write code that incorrectly uses pointers.Its like anything else. You need to consider the meaning and use of a pointer, and only use it in its correct context and initialization.It is true that pointers are a sensitive area, causing problems for many programmers, but the rules are the rules, and if you follow them you can write stable code using pointers.Never use a pointer without initializing it by a call to an allocator.Never use a pointer without checking to see if its initialization failed.Never use a pointer beyond the bounds of its allocation.Always deallocate a pointer after its use has ended.Never use a pointer after it has been deallocated.

What is null object in c plus plus?

a pointer that is not pointing to anything

What changes the pointer to a plus icon in excel?

The application does that when the pointer is over the cells region of the spreadsheet.

What does multiplying a pointer by 5 in C plus plus mean How does it change the pointer's value?

Multiplication is yet another thing, what you should never do with pointers.

Which function is used to determine the position of the put pointer in a file in c plus plus?

The function ftell returns the position of the file pointer for a file.