Computer Terminology
Computer Programming
C Programming

What is null pointer and is it same as an uninitialized pointer?

Top Answer
User Avatar
Wiki User
Answered 2010-08-04 23:52:33

An uninitialized pointer is a pointer that has not been assigned a value; it's uninitialized.

The value of an uninitialized pointer is undefined (it could be anything).

A null pointer is simply a pointer that has a value of NULL.

A word of advice: initialize your pointers to NULL.

This allows you to see that the pointer is invalid; to check if an uninitialized pointer is valid is quite impossible.



int *myPointer;


int *myNullPointer = NULL;

Dereferencing either of these pointers is something you'll like to avoid.

It is very common in a program to check for null pointers; some functions return NULL on failure, for example:

struct Foo *result = doSomething();

if (result == NULL) {

printf("Error: The function doSomething() returned NULL);


} else {

printf("The result: %d", result->bar);


User Avatar

Your Answer

Related Questions

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.

You cannot delete an uninitialized pointer, because there is no allocation for the object, and the pointer contains garbage. That includes the case where you attempted allocation and failed, but deletion is safe in that case because a NULL pointer is "safe" to delete, even though it does not point at anything.

NULL Macro is simply what is defined as 0 in a macro provided by the libraryNull pointer is a pointer which has 0 or NULL value stored and points to nowhwere still it points to 0x00 i.e. the first memory location of the OSNull pointer != Uninitialized pointer because an uninitialised pointer can point anywhere in the memory location ...but a NULL pointer surely points to no where(but still behind the scene we can say that it only points to 0x00). Never we can retrive a Null pointer location using th"&" operator..neither will malloc/calloc return NULL IF THERE IS SPACE IN THE MEMORY. NULL pointer is unique !!

A pointer variable which is declared but not initialized is called a NULL POINTER.ex: int *p;Please don't use the above. A NULL pointer is a specific value assigned to a pointer, just like any other value. NULL is a language-specific designation, and is guaranteed to be comparable to, unlike uninitialized variables, which can have any value.That is:int *a;int *b = NULL;int *c = (int *) malloc(sizeof(char));( a c) is NEVER true.NULL is a reserved word in most high-level languages, and indicates a specific value for assignment. It is commonly used to indicate that something has not yet been assigned a "real" value, or has had its contents deleted. It is an EXPLICIT value, and not just "undefined".In the context of pointers (which, remember, are really memory location addresses), a NULL pointer is one which has NO value, and thus does NOT point to any memory location. The difference between an uninitialized pointer and a NULL pointer is that most common languages do not specify what value an uninitialized pointer has upon creation (many, such as C, are assigned a random value), while a NULL pointer explicitly has NO value (which is the meaning of NULL).Many modern languages and compilers will assign NULL to a pointer upon initialization, but don't count on it. It is sloppy programming to do so, and can lead to many hard-to-find errors.

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

A null pointer is a pointer variable with the value 0. A null macro is a macro that defines the NULL symbol (typically 0L on a 32-bit system).

This was a programming error in Farmville, which has now apparently been fixed.A "null" programming error refers to a special value used in several languages to represent the thing referred to by an uninitialized pointer/database.

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

Unitialized pointer may contain any value, so if you should use them, the results are unpredictable; NULL value on the other hands explicitly means that the pointer does not point anywhere. e.g.: size_t ListLen (const List *p) { size_t len= 0; while (p != NULL) { ++len; p= p->Next; } return len; }

For example, if you write NULl instead of NULL.

There are times when it is necessary to have a pointer that doesn't point to anything. The macro NULL, defined in , has a value that's guaranteed to be different from any valid pointer. NULL is a literal zero, possibly cast to void* or char*.

A NULL pointer has the same size as a non NULL pointer. NULL means that the pointer has been set to the NULL value that is usually zero (0) but the NULL value is at the digression of the compiler manufacture (and may have a value other than zero) so a pointer should always be set to the NULL value and not zero. Current compilers (32 and 64 bit, Intel chip) have a pointer size of 4 (8 bit) bytes. It should be noted that the number of bits in any data type is at the compiler manufactures digression but is heavily influenced by the computer hardware. void *p= NULL; printf ("%d\n", sizeof (p)); or printf ("%d\n", sizeof (void *));

A null pointer is a pointer that holds the value zero (0), which simply means it does not point at anything in particular. It is an error to try and dereference memory address 0x0, as this address is reserved by the system, and will result in undefined behaviour. Pointers must be tested to ensure they hold a non-null address before being dereferenced. An uninitialised pointer is the same as any other uninitialised variable; no value has yet been assigned to it. The value of an uninitialised variable will be whatever value happens to reside in the memory allocated to that variable. All variables, including pointer variables, must be initialised before being accessed for the first time and most compilers will warn against accessing an uninitialised value. Dereferencing an uninitialised pointer has undefined behaviour.

Pointer is a variable that stores address of a variable . A NULL Pointer a pointer that doesn't point to anything, it is a literal zero .Some people ,notably C++ programmers, prefer to use 0 rather than NULL.

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

You haven't assigned the pointer yet, so it's initialized as NULL, or you're trying to assign NULL to the value of the pointer. You have to check if the value is NULL before you use it, or you'll end up with errors just like this.

An uninitialised pointer is a pointer that has been instantiated but has not yet been assigned a valid memory address. If you attempt to dereference whatever address happens to exist in the pointer when it was instantiated, then undefined behaviour will result. This is no different to using any other type of variable that has not yet been initialised. A null pointer is a pointer that has been assigned address zero, which simply means "does not point at any address". int *p; // uninitialised pointer -- do not dereference until initialised!! p = 0; // ok -- points at nothing p = malloc (sizeof(int)); // ok -- holds a valid address or zero if the allocation failed Note: if the result of a malloc is address 0, it means the allocation failed, but the pointer is in a valid state. You should always check a pointer is non-null before attempting to dereference the pointer.

Depends on the language, the value of NULL (actual implementation and its value), and the definition of valid.But in general, a pointer is an int, the value is a memory address of another data type (int, struct, or function, etc).Because a pointer is an int, the value must be one of the integers defined.if you have a derivative like:#define NULL 0then yes, NULL is a valid value for any pointer to functionsbut "valid" is not the same as a "valid value". One may say "valid" means a pointer is pointing to an actual function, hence a pointer pointing to NULL is "Invalid".

A null pointer exception in java comes when you are trying to perform any action on an object that isnt initialized/has a value i.e., is a NULL Value Ex: private String s; //declare a string if(s.equals("test")){ //do something.. } You will get a null pointer in the if condition because you are checking a value that is null which is not allowed..

Starting with a pointer to the pointer to the first element (p1**), verify the first pointer is not null (*p1 != null), retrieve the pointer to the second element (*p2 = * and verify it is also not null (*p2 != null), and then retrieve the pointer to the third element (*p3 = * Note that *p3 might be null, but *p1 and *p2 must not be null, or the swap can not be performed. Note that using pointer to pointer syntax allows you to treat pointer to first element the same as pointer to subsequent element, i.e. to not need to handle the special case. Also, since you do need to modify the pointer, you need a pointer to the pointer. Set *p1 = *p2, *p3 = *p1, and *p2 = *p3. Note that these assignments must be done using the original values, not the intermediate value, so you will need some temp pointers. The end result is that **p1 will be ordered after **p2.

int main (void) { int *p; /* uninitialized pointer */ *p = -1; /* writing to random memory */ return 0; }

A null pointer is a pointer that has been initialised with the NULL value (zero). An uninitialised pointer is one that has not be initialised to any value and will in fact store whatever value happened to reside in the pointer's own memory address at the point of instantiation. Uninitialised pointers are a clear sign of bad programming because the only safe way to determine if a pointer is valid or not is to compare its value with NULL. An uninitialised pointer will almost always be non-NULL, which means you run the risk of accessing memory that either does not belong to you, or is otherwise invalid. Most compilers include a debug switch to warn you when you attempt to access any uninitialised variable, which naturally includes pointer variables. This switch must be on at all times.Whenever you instantiate a pointer, always initialise it straight away, either by nullifying it, or by storing a valid memory address in it. When you are finished with the pointer, it's good practice to nullify it immediately, even if the pointer would subsequently fall from scope. If the pointer is to be immediately re-assigned, there is no need to nullify it (but it's good practice nonetheless). If you follow this practice at all times, you can be assured that any non-NULL pointer will always be pointing at something valid (and if it isn't, then you have some serious problems elsewhere in your code).As a rule of thumb, if you can use a reference rather than a pointer, use a reference. They are much easier to work with. Pointers should only be used if there's any possibility (however remote) that a reference could be NULL, because a NULL reference will completely invalidate your program (pointers can be NULL, but references can never be NULL). This is why functions such as malloc() and calloc(), and the C++ new operator all return pointers rather than references. You can only return a reference when an allocation is guaranteed to succeed, and a dynamic memory allocation simply cannot make that guarantee.

its just an programming error, null definition in Programming is to represent the thing referred to by an uninitialised pointer.

#define NULL ((void *)0) /* defined in <stddef.h> */ const char *mynullvar = NULL;

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.