answersLogoWhite

0


Best Answer

A void pointer is a pointer that has no type information attached to it.

A null pointer is a pointer that points to "nothing". A null pointer can be of any type (void included, of course).

User Avatar

Wiki User

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

Wiki User

10y ago

A NULL pointer is any pointer (including a void pointer) that has been initialised but is not currently pointing at anything valid. A void pointer is one that can be assigned any memory address, regardless of the type stored at that memory address.

All pointers, including void pointers, must be initialised with a valid memory address before they can be used. An uninitialised pointer will store whatever value happens to reside at its own storage location when it is first instantiated and that value will be interpreted as being a memory address of the type indicated by the pointer. However any attempt to access that memory address would be catastrophic, since it could point literally anywhere, including memory that does not belong to your program. Thus programmers need some way to determine when pointers are pointing at something valid. This is achieved by assigning the NULL value (zero) to pointers that are invalid. In this way, any non-NULL pointer can be regarded as being a valid pointer. The onus is therefore upon the programmer to ensure all pointers are non-NULL prior to any indirect accesses, and to ensure all pointers are nullified when they are no longer required.

Void pointers are used when the type being pointed at cannot be determined at compile time. It is up to the programmer to determine the actual type being pointed at runtime, and to cast the pointer accordingly. In most cases, this means utilising runtime type information (RTTI), which naturally incurs a performance overhead. Void pointers are typically used in C. However, in C++, pointers to abstract data types and base classes with virtual interfaces can be utilised instead, thus eliminating any need for RTTI.

This answer is:
User Avatar

User Avatar

Wiki User

12y ago

If by 'void pointer 0' you mean '(void *)0', then it is equal to NULL.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is the difference between null and void pointers?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

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.


What is the Difference between public static void and static public void?

There is no difference between public static void and static public void


What does the error 'Null Pointer Assignment' mean?

The null pointer assignment error means your program has attempted to access a memory address that does not belong to your program. This typically occurs when accessing memory indirectly through a pointer: int* p = nullptr; *p = 42; // Error: null pointer assignment The above is the classic example of this type of error. The null address is typically the all-zeroes address (0x0) but, regardless of the physical address, it must never be accessed because it is a system address. We typically refer pointers to the null address when they are no longer in use or we don't have an address we can (yet) assign to them. Passing unchecked pointers to functions is another common cause: void f (int* p) { *p = 42; // potential error // ... } In the above example there's no guarantee p refers to a non-system address. Although we can easily test p is non-null before accessing it, that won't guarantee p refers to a non-system address. However, we can greatly reduce the risk of error by passing memory address via references instead of pointers: void f (int& r) { r = 42; // ... } There's still potential that r refers to a system address if the address were passed via a pointer, however there is seldom any need to use unchecked pointer variables in C++. References and resource handles (or smart pointers) eliminate the need for pointers and are actually more efficient than pointers because testing for null becomes largely redundant. The only time we really need a pointer is when "no object" is a valid argument: void f (int* p) { if (p == nullptr) { // the "no object" code } else { // code that operates on an object } }


Difference between void and devoid in c plus plus?

There is no such thing as devoid in C++.


What is the difference between a null pointer and a null macro?

Using a NULL macro to make C portableI'll assume that you're asking your question for C type language programming. A NULL pointer is a pointer that's guarnteed to point to nothing. This may be 0 in a UNIX/Linux system or some other address in another system. Using the NULL macro to set/initialize your pointers will make your programs more portable among systems than using something like the 0.#include char *c = 0; // initialize to NULL--not portablechar *p = NULL; // initialize to NULL as defined in stdio is portableAddendumThe code:char *c = 0;actually is portable because the compiler converts 0's used in a pointer context (cast to a pointer) to the machine's representation of a NULL pointer, which may or may not be all 0 bits. The NULL macro itself might be defined as something like 0 or (void *)0, and both definitions are portable. As a corollary, the following code is also portable:if (!c) {// do something}because it is equivalent to:if (c != 0) {// do something}and the 0 above is converted to a NULL pointer because it is being compared with a pointer.

Related questions

Difference between void pointer and null pointer?

A Null pointer has the value 0. void pointer is a generic pointer introduced by ANSI. Before ANSI, char pointers are used as generic pointer. Generic pointer can hold the address of any data type. Pointers point to a memory address, and data can be stored at that address.


Solution to null pointer assignment error?

Answer#ifndef NULL# define NULL ((void*)0)#endifAnswerDon't use pointers that contain NULL-value. Eg:int *myptr= NULL;...*myptr = 32; /* wrong */


What are void pointers?

They are pointers without type


How ca you legalize your null and void marriage?

You cannot "legalize" a null and void marriage. You need to get married "legally".You cannot "legalize" a null and void marriage. You need to get married "legally".You cannot "legalize" a null and void marriage. You need to get married "legally".You cannot "legalize" a null and void marriage. You need to get married "legally".


Where is the null void in fusion fall?

it is in the future. a different future and the null void is a training camp.


What is the difference between void and pore?

no difference


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.


Does a will become null and void after marriage in TX?

Certain clauses of a will made before marriage will be null and void. The wife will be included in the distribution.


If you married at the age of 18 then remarry at the age of 25 with a different man is your marriage both null and void?

A marriage is considered null/void when the previous marriage has not been terminated. An unconsumed marriage also can be considered null/void.


If a police report has numerous errors on it is it null and void?

No, just because a police report has numerous errors does not mean the report is null and void.


What does null and void mean?

According to Black's Law Dictionary, the term "null and void" has become a common redundancy: they mean the same thing.


A sentence with the word null and void?

This personal cheque has been stamped " Null and Void " by the bank because the account has been closed long ago. The lease was declared null and void because both co-owners of the leased property had not signed it.