Best Answer

A pointer is a variable that can store a reference (a memory address) or can store a NULL value (zero). The only use of any pointer in C++ is whenever you need to refer to memory that, for whatever reason, may not be valid. That is, if there is any possibility that a reference could be NULL, then you must use a pointer, because NULL references are invalid in both C and C++.

By way of an example, when you dynamically instantiate a new object at runtime, there is no way to guarantee that a sufficient block of free memory will be available, therefore you cannot reference that memory. For that reason, the new operator returns a pointer, not a reference. This is no different to the way the malloc() function returns a pointer, not a reference, in C.

As well as dynamic allocations, pointers can also be used to pass objects to functions. While programmers are encouraged to pass objects by reference rather than by value, it is sometimes desirable to pass a NULL reference. But since references can never be NULL, a NULL pointer must be passed instead.

Since pointers are variables they are more flexible than references insofar as once a memory address is assigned to a reference, that reference cannot refer to any other memory address while it remains in scope. But pointers can be assigned to point at any reference, including a NULL reference, at any time.

User Avatar

Wiki User

โˆ™ 2013-03-28 21:24:53
This answer is:
User Avatar
Study guides
See all Study Guides
Create a Study Guide

Add your answer:

Earn +20 pts
Q: What are Uses of pointer in c plus plus?
Write your answer...
Still have questions?
magnify glass
Related questions

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 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.

What is 'this' pointer in c plus plus?

Address of the current object.

Function pointer in c plus plus?

Yes, C++ supports function pointers.

What are the uses of a pointer in c?

Accessing data by address.

What is null object in c plus plus?

a pointer that is not pointing to anything

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.

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.

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.

What is pointer in C plus plus?

A pointer is a variable that holds an address in memory. int * pPointer = new int; This code creates a pointer to an integer, and assigns it an address of an integer object on the heap.

What is this operator in C plus plus?

The this operator in C++ is a compiler generated pointer to the instance of an object, accessible from within a method of that object.

Uses of pointers?

In computer terminology, pointer is a programming language. It is an important part of C language. Uses of pointers: C pointer, C arrays, C linked list, memory-mapped hardware, Pass-by-address using pointers, Dynamic memory allocation.

What is difference between direct addressing and indirect addressing in c plus plus?

Indirect addressing uses a pointer. Indirectly accessing the memory being pointed at is known as dereferencing. Direct addressing uses a variable's name or a reference to obtain the value.

What is double pointer in c plus plus?

A double pointer is a pointer which points to another pointer which points to an object.For example:Foobar** foobar = NULL;This means that somewhere in memory, the class foobar has been created. The variable 'foobar' now points to a pointer to that memory. However, in this example, the pointer is created as 0.

What is called pointers-c plus plus?

A pointer in C++ is the same as a pointer in C -- it is a variable that is used to store a memory address and which allows indirect access to that memory address. When a pointer is not in use, it must be zeroed or nullified by assigning the NULL value, thus preventing indirect access to invalid memory.

What is pointer to class in c plus plus?

You cannot point at a class. Pointers are defined by the class of object they can point at. An object is an instance of a class and the pointer points at the object, not the class.

What is an iterator in c plus plus?

An iterator is a type of pointer that is used to iterate or traverse an array or list of objects.

Do you have pointer concept in c plus plus language?

Yes. All string variables are pointers as are other arrays.

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).

Which operator can not be overload in c plus plus?

There are 7 C++ operators that connot be overloaded. They are... . select .* pointer select :: scope :> base ?: conditional # preprocessor ## preprocessor

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.

Call by reference using pointer in c plus plus?

Example: 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

What is the concept of asterisk in c plus plus?

An asterisk in C++, such as int *data, is what's known as a pointer. A pointer is like a regular variable, but instead of holding a value, a pointer holds the memory location of the value. It's a somewhat difficult concept, and you can learn more about it here: See related links section below...

Which operator not overloaded in c plus plus?

The operators that cannot be overloaded in C++ are:. member selection.* pointer to member selection:: scope resolution:> base?: conditional# preprocessor## preprocessor