Categories:
.NET (357)
C (330)
C++ (183)
CSS (84)
DBA (2)
General (7)
HTML (4)
Java (574)
JavaScript (106)
JSP (66)
Oracle (114)
Perl (46)
Perl (1)
PHP (1)
PL/SQL (1)
RSS (51)
Software QA (13)
SQL Server (1)
Windows (1)
XHTML (173)
Other Resources:
What is a dangling pointer? C++
What is a dangling pointer? C++
✍: Guest
A dangling pointer arises when you use the address of an object after its lifetime is over. This may occur in situations like returning addresses of the automatic variables from a function or using the address of the memory block after it is freed. The following code snippet shows this: class Sample { public: int *ptr; Sample(int i) { ptr = new int(i); } ~Sample() { delete ptr; } void PrintVal() { cout << "The value is " << *ptr; } }; void SomeFunc(Sample x) { cout << "Say i am in someFunc " << endl; } int main() { Sample s1 = 10; SomeFunc(s1); s1.PrintVal(); } In the above example when PrintVal() function is called it is called by the pointer that has been freed by the destructor in SomeFunc.
2012-01-06, 2629👍, 0💬
Popular Posts:
What is Service Oriented architecture? “Services” are components which expose well defined interface...
Can we use the constructor, instead of init(), to initialize servlet? Yes , of course you can use th...
How To Run "mysql" Commands from a Batch File? - MySQL FAQs - Command-Line End User Interface mysql ...
Have you ever worked with Microsoft Application Blocks, if yes then which? Application Blocks are C#...
How To Blend a Color Layer to a Image? - PSP Tutorials - Fading Images to Background Colors with PSP...