answersLogoWhite

0


Best Answer

You'd get a memory access violation. Nothing serious besides the fact that your program crashes (which is a good thing).

User Avatar

Wiki User

8y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is the effect of dereferencing a null pointer variable?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

What is pointer initialization?

Assigning an initial value to a pointer variable. Example: int *p= NULL;


What is dangling pointer reference?

Whenever memory that was in use, and was referred to by a pointer variable, is freed, and the pointer variable is not updated accordingly (setting it to NULL, for example), the pointer variable is considerred to be a dangling pointer reference.


What is null pointer assignment?

This error message means that somewhere in your program you have used a pointer-varible containing NULL-value. (Within an actual OS it with stop the program immediately, but in MS-DOS it doesn't.)


What is the difference between uninitialized pointer and null pointer in c language?

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.


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.

Related questions

What is a segmentation fault?

An error in which a running program attempts to access memory not allocated to it and core dumps with a segmentation violation error. This is often caused by improper usage of pointers in the source code, dereferencing a null pointer, or (in C) inadvertently using a non-pointer variable as a pointer.


What is a segment fault?

An error in which a running program attempts to access memory not allocated to it and core dumps with a segmentation violation error. This is often caused by improper usage of pointers in the source code, dereferencing a null pointer, or (in C) inadvertently using a non-pointer variable as a pointer.


What is the use of null pointer?

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.


What is pointer initialization?

Assigning an initial value to a pointer variable. Example: int *p= NULL;


What is a NULL Pointer Whether it is same as an uninitialized pointerin C language?

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.


What is the by default value of globally declaration variable?

int, float: 0 pointer: NULL


What is dangling pointer reference?

Whenever memory that was in use, and was referred to by a pointer variable, is freed, and the pointer variable is not updated accordingly (setting it to NULL, for example), the pointer variable is considerred to be a dangling pointer reference.


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 null pointer assignment?

This error message means that somewhere in your program you have used a pointer-varible containing NULL-value. (Within an actual OS it with stop the program immediately, but in MS-DOS it doesn't.)


What is the difference between uninitialized pointer and null pointer in c language?

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.


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.


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.