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.
Dereferencing a pointer returns the value stored at the memory address held by the pointer. This is also known as indirection.
Example usage:
int i = 42; // an integer
int * p = &i; // a pointer to the integer
std::cout<<"Address of i: 0x"<<&i<<std::endl;
std::cout<<"Value of i: "<<i<<std::endl;
std::cout<<"Address of p: 0x"<<&p<<std::endl;
std::cout<<"Value of p: 0x"<<p<<std::endl;
std::cout<<"Dereferenced value of p: "<<*p<<std::endl;
Note that only pointer variables can be dereferenced. Normal variables like i cannot be dereferenced because they are not pointers.
A pointer is a variable or constant that is used to store a memory address. We call them pointers because they literally "point at" the address. Dereferencing a pointer returns a reference to that address, thus allowing the contents of that address to be read or written to. Dereferencing a pointer is also known as indirection as it allows us to indirectly access the memory address.
http://rapidshare.com/files/154681843/C_Basic_Books_Must_download_it.rar
These books contain the basics of C language with general answers , must read it !
dangling pointer is a pointer
The pointer that points to a block of memory that does not exist is called a dazzling pointer or wild pointer
This could lead to a memory leak
When we call non static method with respect to class object then this pointer is created which keep the reference of that object.
Not to be pedantic, but you cannot call a destructor explicitly. Destructors are implicitly called when an object falls from scope or when you delete a pointer to an object. Any object created dynamically (with the new keyword) must be deleted as soon as you are finished with it, and before the pointer falls from scope. In this sense, you are explicitly calling the object's destructor, however it's really being called implicitly by you deleting the pointer. It's also good practice to explicitly NULL your pointer immediately after deleting the object it pointed to. An object reference is destroyed automatically when the reference falls from scope. If you have a pointer to that reference, do not delete the pointer, but do assign it to NULL as soon as possible to prevent any access to the deleted object. If you do delete a pointer to a reference that's still in scope, you will render the reference NULL and a NULL reference will render your program invalid.
You cannot store references. A reference is nothing more than an alias, an alternate name for an existing variable or constant. References are primarily used when passing variables to functions such that the function can operate upon the variable itself -- known as passing by reference. The function refers to the variable by a different name, an alias, but it is the same variable. By contrast, when passing a variable by value the function uses a copy of that variable, assigning the variable's value to that copy. References are often confused with pointers, primarily because C uses the term to mean a pointer (hence the term, dereferencing). But in C++ a reference is a separate entity altogether. Unlike a reference, a pointer is a variable in its own right, one that can be used to store a memory address. Since a pointer has storage, you can store a pointer in a data file. However, in reality you are only storing the pointer's value -- a memory address -- not an actual pointer. Pointers and references are similar insofar as they can both refer to an object. A pointer does this by storing the memory address of the object, while a reference refers directly to the object itself. Thus if you have a pointer and a reference to the same object, the pointer's value is exactly the same as the address of the reference. Therefore the only way you can store a reference is by storing the object being referred to, not the reference itself.
A dangling pointer (we also use the terms stray pointer and wild pointer) is created whenever we call delete on a pointer and then try to use the pointer without reassigning it.We can also create dangling pointers inadvertently by calling a rogue function that returns a pointer to an object that is local to the function we are calling. The object will fall from scope when the function returns so the pointer is left dangling.Note that there is no such thing as a dangling pointer reference. Pointers and references are not the same. A reference is merely an alias to an object -- it consumes no memory beyond the object it refers to. Whereas a pointer is a variable that may contain the address of an object, but it requires additional memory to do so (4 bytes on 32-bit architecture). Pointers may be NULL, references can never be NULL. Pointers to valid objects require indirection, references do not. References are the preferred method of accessing an object's members, not least because they are easier to work with.
A dangling pointer occurs when objects have been deallocated or deleted from the system. They 'dangle' due to the pointer's values still remaining leaving a location to the non-existent object in the memory.
The pointer that points to a block of memory that does not exist is called a dazzling pointer or wild pointer
I think you're referring to the C/C++ concept of "dangling pointers." This is when you allocate some memory to a pointer, then deallocate that memory, but don't change the pointer. This causes any attempted use of the pointer to return an unused memory address. There is no such concept in Java, since the programmer has little to no control over how memory is allocated or freed. The closest thing I can think of is if you're using a class such as a Reader, in which you can close the object (Reader.close()) and then still have a reference to it. But in this case (and other similar cases) attempting to use the Reader further will result in an IOException being thrown.
pointer: to access data by address reference: there is no reference in C language
This could lead to a memory leak
No, call-by-reference can be emulated with pointers.
By declaring an integer pointer you are declaring that any non-zero reference stored in the pointer is guaranteed to be an integer reference. In order to guarantee the reference is actually a structure, the pointer must be declared as such, because casting an integer to a structure can never be regarded as being type-safe.
Example: void foo( MyClass& object ){} // function with call by reference signature MyClass* p = new MyClass(); // instantiate a pointer to MyClass foo( *p ); // call by reference using the pointer
In JAVA, all variables are reference variables, and there are no pointer variables. Even though the platform may implement them as pointers, they are not available as such. In C, no variables are reference variables. They are a C++ enhancement. In C++ a reference variable is syntactically the same as a pointer variable, except that the use of the indirection operator (*) is implicit. You do declare reference variables slightly differently than pointer variables but, once you do so, they can be treated as non-pointer variables. Reference variables also cannot be redefined once they have been initialized to point to some object. They are const. Structurally, there is no difference between a pointer variable and a reference variable. They are both still pointers. The compiler just makes it easier to treat reference variables and non-pointer variables the same way.
A dangling pointer is one that points to a memory location but the memory itself has been freed or released back to the system. The memory may still contain valid information, but the system can overwrite the data at any time so any attempt to access that memory via the dangling pointer could prove disastrous. As soon as memory is released, the pointer is invalid -- because the memory it points to is potentially invalid. To prevent this, always nullify pointers (set them to point at memory address zero) when they are no longer required, immediately after releasing the memory they point to. There are occasion when this is not necessary, such as when releasing a member pointer in a class destructor, but if a pointer is re-used, it must be initialised before being accessed again.
When we call non static method with respect to class object then this pointer is created which keep the reference of that object.