answersLogoWhite

0


Best Answer

In the case of C, execution halts with a segmentation fault because the literal address of NULL is never allocated to a running program.

User Avatar

Wiki User

15y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Can you deallocate memory of a null pointer?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

What is called pointers-c plus plus?

Yes, C++ has pointers, which are references to memory locations. which are variables that store memory addresses, or NULL (zero). If the pointer is non-NULL, the pointer is said to dereference the object (or variable) residing at the stored memory address, which permits indirect access to that object so long as the object remains in scope.


What is NULL array in C Language?

There is no "NULL array" as such, you may take a pointer to an array and set it to NULL (binary 0) e.g. int* foo; // Declare a pointer foo = malloc( 40 * sizeof(int)); //Allocate an array of 40 integers pointed to by "foo" foo = NULL; //Set the pointer to NULL, if you're using a garbage collector this should trigger an automatic free() of the memory allocated to the array. If you are NOT using a garbage collector (which is more common in C) this line is a memory leak.


What is stray pointer?

stray pointer is a that pointer which pin points nothing or anywhere but we dont know... for example: int *ptr; ptr=new int[10]; //this memory is on heap. and at the end of the programm if we dont delete this memory mean to say if we dont deallocate this memory then this type of pointer is pointing towards nothing or anywhere because when we work on heap deletion of pointer is must if we dont delete pointers than they pin point stray or anywhere so that sort of pointer is stray pointer. i think you understand...


Do reference variables occupy memory in c?

All references must be non-null, therefore they will always have memory allocated to them. A reference is simply a non-null memory location that stores a specific type of variable, as determined by the reference's type. The reference name is an alias (a token) for the memory location, in much the same way that an array name is an alias for the starting address of the array. A pointer variable is different in that memory must be set aside for the pointer variable itself, in addition to the memory it actually points to. On a 32-bit system, 4 bytes must be allocated to every pointer variable, to store the memory address that they point to, which could be null. But references only occupy the memory they actually refer to, which can never be null (a null reference will in fact render the program invalid).


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.

Related questions

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

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 !!nishantnitb@aol.com


What is called pointers-c plus plus?

Yes, C++ has pointers, which are references to memory locations. which are variables that store memory addresses, or NULL (zero). If the pointer is non-NULL, the pointer is said to dereference the object (or variable) residing at the stored memory address, which permits indirect access to that object so long as the object remains in scope.


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.


33 What does the error 'Null Pointer Assignment' mean and what causes this error?

This error appears due to incorrect assignment to pointer and pointer tries to access illegal memory...


What is NULL array in C Language?

There is no "NULL array" as such, you may take a pointer to an array and set it to NULL (binary 0) e.g. int* foo; // Declare a pointer foo = malloc( 40 * sizeof(int)); //Allocate an array of 40 integers pointed to by "foo" foo = NULL; //Set the pointer to NULL, if you're using a garbage collector this should trigger an automatic free() of the memory allocated to the array. If you are NOT using a garbage collector (which is more common in C) this line is a memory leak.


What is stray pointer?

stray pointer is a that pointer which pin points nothing or anywhere but we dont know... for example: int *ptr; ptr=new int[10]; //this memory is on heap. and at the end of the programm if we dont delete this memory mean to say if we dont deallocate this memory then this type of pointer is pointing towards nothing or anywhere because when we work on heap deletion of pointer is must if we dont delete pointers than they pin point stray or anywhere so that sort of pointer is stray pointer. i think you understand...


What are the advantages of pointers in a program?

A pointer is simply a variable that stores a memory address and that allows that memory to be dereferenced. Unlike a reference, which must always refer to the object assigned to it, a pointer can refer to any object of the pointer's type, including null. A null pointer is simply a pointer that does not refer to any object. In languages that do not support pass by reference (such as C), pointers must be used to pass objects to functions. The pointer is passed by value, but the value is a memory address, which is the same as passing the object at that address. In languages that do support references (such as C++), references are useful when you need to guarantee an object exists because a reference can never be null. However, when passing an object to a function as an optional parameter, you must use a pointer because pointers can be null. Programmers must test pointers to ensure they are non-null before attempting to dereference them. References do not need to be tested; if a reference exists, it must refer to an object in memory.


How many bytes does null occupy?

In most languages with a null reference, it is simply a memory address to a zero-length memory block. So the only memory it would occupy in these cases would be enough for a memory pointer: usually around 4 bytes.


Do reference variables occupy memory in c?

All references must be non-null, therefore they will always have memory allocated to them. A reference is simply a non-null memory location that stores a specific type of variable, as determined by the reference's type. The reference name is an alias (a token) for the memory location, in much the same way that an array name is an alias for the starting address of the array. A pointer variable is different in that memory must be set aside for the pointer variable itself, in addition to the memory it actually points to. On a 32-bit system, 4 bytes must be allocated to every pointer variable, to store the memory address that they point to, which could be null. But references only occupy the memory they actually refer to, which can never be null (a null reference will in fact render the program invalid).


What is null point?

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.


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.


Is it possible to delete a const object in C plus plus?

Yes. However, making a const pointer seems rather pointless, as you will be able to allocate and deallocate memory for it, but you will be unable to change the contents.