Tuesday, July 14, 2009

What is wild pointer , Null Pointer,Void pointer & Dangling Pointer? How can we distinguish between them?

Related To Pointer in c

What is wild pointer , Null Pointer,Void pointer %26amp; Dangling Pointer? How can we distinguish between them?
In computer science, a pointer is a programming language datatype whose value refers directly to ("points to") another value stored elsewhere in the computer memory using its address. Obtaining the value that a pointer refers to is called dereferencing the pointer. A pointer is a simple implementation of the general reference datatype (although it is quite different from the facility referred to as a reference in C++).





Null Pointer


A null pointer has a reserved value, often but not necessarily the value zero, indicating that it refers to no object. Null pointers are used routinely, particularly in C and C++, to represent exceptional conditions such as the lack of a successor to the last element of a linked list, while maintaining a consistent structure for the list nodes. This use of null pointers can be compared to the use of null values in relational databases and to the "Nothing" value in the "Maybe" monad. In C, each pointer type has its own null value, and sometimes they have different representations.





Because it refers to nothing, an attempt to dereference a null pointer can cause a run-time error that usually terminates the program immediately (in the case of C, often with a segmentation fault, since the address literally corresponding to the null pointer will likely not be allocated to the running program). In Java, access to a null reference triggers a Java.lang.NullPointerException, which can be caught (but a common practice is to attempt to ensure such exceptions never occur). In safe languages a possibly null pointer can be replaced with a tagged union which enforces explicit handling of the exceptional case; in fact, a possibly-null pointer can be seen as a tagged union with a computed tag.





A null pointer should not be confused with an uninitialized pointer: a null pointer is guaranteed to compare unequal to a pointer to any object or function, whereas an uninitialized pointer might have any value. Two separate null pointers are guaranteed to compare equal.





Void Pointer


a void pointer (void *), which indicates that it is a pointer to a region of unknown data type. This pointer is typically cast to a more specific pointer type by the programmer before being used.


malloc returns a void pointer





Dangling Pointer


A reference that doesn't actually lead anywhere. In C and some other languages, a pointer that doesn't actually point at anything valid. Usually this happens because it formerly pointed to something that has moved or disappeared, e.g. a heap-allocated block which has been freed and reused.





Hope this will satisfy you.





R. Nag MS (Comp. Sc)


No comments:

Post a Comment