Best Answer

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.

User Avatar

Wiki User

โˆ™ 2007-07-09 11:23:01
This answer is:
User Avatar
Study guides
See all Study Guides
Create a Study Guide

Add your answer:

Earn +20 pts
Q: What is dangling pointer reference?
Write your answer...
Related questions

What is dangling pointer?

dangling pointer is a pointer

What is dangling pointer reference in c plus plus?

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.

What is dazzling pointer in c?

It is "dangling".

Definition of dangling pointer object?

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.

When would you use a pointer and a reference variable?

pointer: to access data by address reference: there is no reference in C language

Dangling reference in java?

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.

What dire consequences could result from dereferencing a dangling pointer?

This could lead to a memory leak

What happens if we use an integer pointer as a member of structure instead of structure pointer?

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.

What is the difference between a reference and a pointer in c?

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.

Why you use double pointer instead of pointer?

Double pointers are better known as pointer-to-pointer types. You use pointers to store the memory address of an object but when the object is itself a pointer, you need to use a pointer-to-pointer in instead. Pointer-to-pointer types are typically used when passing pointers into functions. Pointers allow you to pass objects to functions by reference but the pointer itself is passed by value. If you want to pass the pointer by reference, you need to pass a pointer-to-pointer.

What is pointer and pointer types and uses of pointer and the meaning of pointer?

As the name suggests Pointer is used to point towards something ,here in this case it points to another variable and stored at a memory location. Pointer is a variable that stores address of another variable. Different Types of pointers are: 1)Dangling Pointers 2)NULL Pointers 3)This Pointer 4)Generic Pointer 5)Near Pointer 6)Far Pointer

Is call by reference supported by pointer?

No, call-by-reference can be emulated with pointers.

Explain reference variable and how it is different from pointer variable?

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.

What is a dangling pointer in C and C plus plus?

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.

In 'C' language what is a pointer?

A pointer is a reference to some chunk of memory on your computer. To actually get the value out of said chunk of memory, you must dereference it (i.e. *pointer).

Call by reference using pointer in c plus plus?

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

What is the difference between a pointer and de-reference pointer?

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.

When does this pointer get created?

When we call non static method with respect to class object then this pointer is created which keep the reference of that object.

Should you explicitly call a destructor in C programming?

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.

How do you update a data file in c plus plus with a reference?

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.

Define dangling if in terms of java?

A dangling reference is less problematic in Java, because the garbage collector will eventually delete any object that is unreachable. So, even if one object has a reference to a second object, and the second has a reference to the first object, they would eventually be destroyed if they are unreachable from the objects referenced on the stack.A dangling reference is less problematic in Java, because the garbage collector will eventually delete any object that is unreachable. So, even if one object has a reference to a second object, and the second has a reference to the first object, they would eventually be destroyed if they are unreachable from the objects referenced on the stack.A dangling reference is less problematic in Java, because the garbage collector will eventually delete any object that is unreachable. So, even if one object has a reference to a second object, and the second has a reference to the first object, they would eventually be destroyed if they are unreachable from the objects referenced on the stack.A dangling reference is less problematic in Java, because the garbage collector will eventually delete any object that is unreachable. So, even if one object has a reference to a second object, and the second has a reference to the first object, they would eventually be destroyed if they are unreachable from the objects referenced on the stack.

What is the difference between an relative reference?

absolute reference is the adress or pointer that does not changes while relative reference changes when the target item is moved or the relationship to it has changed

What is actually passed to a function when an object is passed to a function through a pointer?

When an object is passed to a function by pointer, a copy of the pointer's value is passed to the function. Pointers are always passed by value, but because the value is a memory address than can be dereferenced, they enable us to pass objects by reference. In languages such as C which have no concept of references, this was the only way to pass by reference. C++ introduced proper references (aliases for existing objects), thus when we want to pass by reference we can choose to use a pointer or an actual reference. Normally we'd only pass by pointer when passing an optional argument that defaults to NULL when no argument is given. Otherwise we pass by reference because references can never be NULL.

What is an alias name given to a variable in opp with c plus plus?

An alias is a reference, an alternate name for a variable or constant. You can assign the address of any variable or constant to a reference of the same type. A reference is a bit like a constant pointer to the type but, unlike a pointer, a reference has no address of its own thus you cannot store references. More importantly, references can never be NULL. They are simply an alternative name by which you can refer to an existing variable or constant. When you assign a value to an existing reference to a variable, you are assigning the value to the variable itself. When you pass a reference to a function, you are passing the address of the value being referred to, and that address is assigned to the function's reference argument and is local to the function. This is not unlike passing a pointer, but pointers may be NULL, references are guaranteed to be non-NULL (a NULL reference invalidates your program). Note that C++ references are not the same as C reference variables or constants. In C, a reference variable is simply a non-const pointer, while a reference constant is a constant pointer. Hence pointers can be dereferenced (both in C and C++). But in C++, a reference is neither a variable nor a pointer, but is constant (it always refers to the same object and cannot be reassigned once assigned).

How can you change values in call by reference?

We don't call by reference, we call functions. The arguments passed to the function are passed (not called) either by value or by reference, depending upon the function signature (the prototype). When you pass by reference you are passing the actual variable, not a copy of the variable, thus the function can modify that variable's value directly. The only exception is when the parameter is declared a constant reference. Passing a pointer is essentially the same as passing by reference, however the pointer itself is passed by value. To pass a pointer by reference you must pass a pointer-to-pointer instead. Passing by value always copies the value, whether it is declared constant or not. But if it is declared constant, the function might as well accept a constant reference. Passing objects (instances of a class) by constant value will incur a performance penalty in making an unnecessary copy. If it is constant, there is little point in copying the object.