Pointers such as Dangling, Void, Null, and WildDangling pointerA dangling pointer is a pointer that points to a deleted (or freed) memory location. Pointer can function as a dangling pointer in three ways. 1. De-allocation of memory C++ Code 2. Function Call C++ Code C Code Output: A garbage Address If x is a static variable, the above problem does not occur (or p does not become dangling). C++ Code Output: 5 3. Variable goes out of scope Void pointerVoid pointer is a specific pointer type - void * - a pointer that points to an unspecified data location in storage. The type is referred to as void. Basically, the data that it points to can be anything. If we assign a char data type address to a void pointer, it will become a char pointer, an int data type address will become an int pointer, and so on. Because any pointer type can be converted to a void pointer, it can point to any value. Important Considerations
C++ Code Output: Integer variable is = 4 Float variable is= 5.500000 NULL pointerC++ Code Output: The value of ptr is (nil) Important Considerations
Wild pointerA wild pointer is one that has not been initialised to anything (not even NULL). The pointer may be set to a non-NULL garbage value that is not a valid address. C++ Code |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India