Computer Terminology
C Programming

What dire consequences could result from dereferencing a dangling pointer?


Top Answer
User Avatar
Wiki User
2008-12-26 18:13:14
2008-12-26 18:13:14

This could lead to a memory leak

User Avatar

Related Questions

An uninitialized pointer is the same as any other uninitialized variable. It has no definite value. Using (or dereferencing) an uninitialized pointer can result in bad results or damage to some unknown area of the program, data, or operating system, or it can result in a bus fault.

An uninitialized pointer is a pointer that has not been assigned a value; it's uninitialized.The value of an uninitialized pointer is undefined (it could be anything).A null pointer is simply a pointer that has a value of NULL.A word of advice: initialize your pointers to NULL.This allows you to see that the pointer is invalid; to check if an uninitialized pointer is valid is quite impossible.Examples:Uninitialized:int *myPointer;Null-pointer:int *myNullPointer = NULL;Dereferencing either of these pointers is something you'll like to avoid.It is very common in a program to check for null pointers; some functions return NULL on failure, for example:struct Foo *result = doSomething();if (result == NULL) {printf("Error: The function doSomething() returned NULL);return;} else {printf("The result: %d", result->bar);}

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.

When a pointer to a data type that requires four bytes is declared, the compiler knows that the target object is four bytes in size. When the program then performs a calculation to offset the pointer, such as to add 3 (for instance) to the pointer, the generated code actually adds 12. This is because the compiler assumes that adding or subtracting numbers to or from a pointer is an attempt to use the pointer in an array context. (Actually, this behavior is defined in the language specification.)The other valid arithmetic manipulation of a pointer is subtraction of two pointers to the same type of object. In this case, again, an internal multiplier of 4 is applied, and the result is an offset that could be used if the first pointer were the base of an array of those objects.The size of the target object could be any value, such as a double which might be 8 bytes. The compiler will do the arithmetic correctly.Also, keep in mind the distinction between the size of the pointer and the size of the object to which the pointer points. This answer assumes the latter.In any case, the programmer must insure that the calculation results in a pointer or offset value that represents an address in the base object array, assuming that the allocated space of that object is correct. Any other result is inconsistent with the defined usage of a pointer, and the result of dereferencing such an inconsistent pointer or offset is undefined by the language specification, and could result in corruption, incorrect behavior, or crash.

A double pointer has two basic meanings. One is ofa pointer to a pointer, where changing the value ofdouble pointer will result in the original pointer being changed. Another is that of a two-dimentional array, such as a matrix, or a list of char* (e.g. in main when you use argv).

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.

The consequences will be good. The ozone will try and heal itself.

What harmful consequences might result from naïve acceptance of the myth of the ecologically noble savage?

effect, outcome, result, upshot

Result could replace consequences.

An uninitialised pointer is a pointer that has been instantiated but has not yet been assigned a valid memory address. If you attempt to dereference whatever address happens to exist in the pointer when it was instantiated, then undefined behaviour will result. This is no different to using any other type of variable that has not yet been initialised. A null pointer is a pointer that has been assigned address zero, which simply means "does not point at any address". int *p; // uninitialised pointer -- do not dereference until initialised!! p = 0; // ok -- points at nothing p = malloc (sizeof(int)); // ok -- holds a valid address or zero if the allocation failed Note: if the result of a malloc is address 0, it means the allocation failed, but the pointer is in a valid state. You should always check a pointer is non-null before attempting to dereference the pointer.

The Black Death hit Europe in the mid 14th century with devastating consequences Which of the following was not a result of this plague?

There are actually a number of causes for dangling modifiers: some are dangling participles, dangling gerunds, dangling infinitives, and misplaced modifiers. In all cases, they result in sentences that are unintentionally funny. My favorites are: I heard it was going to rain on the radio. (Misplaced: "on the radio" should be next to "heard" unless you have a radio with a big rain cloud over it.) Sandy was walking her dog in a really short skirt. (Misplaced: this sentence seems to say the dog was wearing a really short skirt, rather than Sandy.) Having broken its leg, we took the dog to the hospital. (Dangling gerund-- did WE break the dog's leg?) A clean coffee pot is necessary to enjoy a good cup of coffee. (Dangling infinitive-- where's the subject in this sentence? Who is drinking the coffee-- the coffee pot?)

There are several health consequences one could develop as a result of exposure to chemical. A person could get cancer, infertility, chemical burns, etc.

The frequency of a behavior is the result of the behavior's consequences, or the effect of the behavior

i think u get jail, but not as much as u should..........

Will result in not being allowed to continue in the exam, and that will class as a fail and result in you doing a re take if the school will take you.

Revolutions bring change. It may not always bring the desired change and there are often unintended consequences as a result.

Pointers are often misunderstood or mistreated by programmers, as they require a measure of care to ensure that they are used correctly. The most common causes of buffer overflows, general protection faults, and other program crashes or unexplained behavior can all be linked to the incorrect use of pointers. Freeing a pointer without setting it to null, for example, can result in a "dangling pointer", where it points to an area of memory that may have been allocated to a different memory structure. Miscalculating the size of a memory structure can cause data corruption or unusual program behavior. Therefore, pointers are often referred to as "dangerous", even though there is no harm in using pointers when they are used correctly.

effects, results, wake, consequences, outcome, sequel, end result, upshot

Copyright ยฉ 2020 Multiply Media, LLC. All Rights Reserved. The material on this site can not be reproduced, distributed, transmitted, cached or otherwise used, except with prior written permission of Multiply.