Categories:
.NET (961)
C (387)
C++ (185)
CSS (84)
DBA (8)
General (31)
HTML (48)
Java (641)
JavaScript (220)
JSP (109)
JUnit (31)
MySQL (297)
Networking (10)
Oracle (562)
Perl (48)
Perl (9)
PHP (259)
PL/SQL (140)
RSS (51)
Software QA (28)
SQL Server (5)
Struts (20)
Unix (2)
Windows (3)
XHTML (199)
XML (59)
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, 2481👍, 0💬
Popular Posts:
What are some uses of Intranets & Extranets? An "intranet" is the generic term for a collect...
How do you handle change request? Normally change request are handled by preparing an Impact analysi...
How to make elements invisible? Change the "visibility" attribute of the style object associated wit...
How do we configure “WebGarden”? “Web garden” can be configured by using process model settings in...
How to convert a Unix timestamp to a Win32 FILETIME or SYSTEMTIME? The following function converts a...