Top Answer
User Avatar
Wiki User
2015-01-10 04:02:10
2015-01-10 04:02:10

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.


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.

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.Examples:Uninitialized:int *myPointer;Null-pointer: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);return;} else {printf("The result: %d", result->bar);}

difference between pointer or structure

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.

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

1. pointer to a constant means you can not change what the pointer points to 2. constant pointer means you can not change the pointer.

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.

Pointer holds an address Array holds values

The former is variable, the latter is constant.

Generic pointer of type 'void *' is compatible with any (data-)pointer, but you cannot use the following operators on it: + - ++ -- += -= * -> []

There is no similarity between the two.

The difference that i learnt very recently and the one i remember :-)Reference cannot be changed whereas pointer value can be changed.Actually, const pointer = reference.

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

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; }

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

It means that it doesn't have certain value. It's a mistake when you don't initialize your pointers.Example:uninitialized pointerdouble *p; initialized pointerdouble *p = 1;

A pointer is a variable. A structure is a type.

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

... 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 pointer is an object that contains the address of another object. A deference'ed pointer is an object. It was a pointer, but its address was used to locate and use that other object as if it was the original target of the instruction.

In 8086 programming (MS DOS), a far pointer is normalizedif its offset part is between 0 and 15 (0xF).

pointer is use to hold address of another variable whereas array is a collection of elements of similar datatype

--> Array is a collection of same kind of data.--> Pointer is a memory location where the data stored in the memory

A pointer to a function is the memory address that stores the address of a function, while the pointer itself is a function pointer.A pointer to a function might be defined as "int (*pf)(int, int);", while to actually point to the function, you would use a function pointer, such as "pf = &func;".

Copyright ยฉ 2020 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.