Top Answer
User Avatar
Wiki User
Answered 2013-03-28 21:24:53

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

Your Answer

Related Questions

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

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

Yes, C++ supports function pointers.

Accessing data by address.

a pointer that is not pointing to anything

Address of the current object.

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.

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

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

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.

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.

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.

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

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.

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.

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.

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

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

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

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

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

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

C++ uses the postfix increment operator whereas ++C uses the prefix increment operator. Both do exactly the same thing; they increment C (the same as C=C+1 increments C). The difference is only in the return value. ++C returns a reference to C, whereas C++ returns the original value of C.

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.

Yes. If the ports are memory mapped, then you simply need a pointer to that address, and you need to declare the pointer as volatile. If they are I/O mapped, then you need to create an _asm{} block.

Copyright ยฉ 2021 Multiply Media, LLC. All Rights Reserved. The material on this site can not be reproduced, distributed, transmitted, cached or otherwise used, except with prior written permission of Multiply.