free geoip

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
What is a Dangling pointer? Briefly explane with example.
VU Help • House Banner VU Help Virtual University Students - Assignments, Solved Papers, GDB & Exam Help Student Help Forum • Collaborative • Free Support
#1
A dangling pointer is a pointer which has been allocated but does not point to any entity. For example un-initialized pointer.
int * ptr;
*ptr = 10;

The correct way of doing so is:
int * ptr;
int a;
ptr = &a;
*ptr = 10;


Another example can be a function returning reference of a local variable. The local variables are destroyed when function call ends, so if you try to access that location which has been deleted, it may lead you to unpredictable results.

Code:
int * function() { int a = 10; return &a; } int* ptr = function(); *ptr = 5;

0300-9520262
Get solution in 24 hour
|cpmputer & internetConfusedmileys81:[SIZE="4"][SIZE="3"]....[/SIZE][/SIZE]
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Dangling Pointers Explain in C++ Vuhelper 0 7,293 05-31-2012, 01:52 AM
Last Post: Vuhelper
  Explain the difference b/w Null Pointer and Null Nodes? C++ 2012 Vuhelper 0 1,971 01-06-2012, 12:24 AM
Last Post: Vuhelper
  call by value, call by reference,call by pointer in data structure 2012 Vuhelper 0 4,352 01-04-2012, 10:28 PM
Last Post: Vuhelper
  Pointer question?? Vuhelper 0 1,447 08-30-2011, 09:55 PM
Last Post: Vuhelper
  C++ have Virtual Function vs Function Pointer call 2011 Xpert 0 5,938 05-12-2011, 09:03 PM
Last Post: Xpert
  what is cursor and why we use it. what is difference between cursor and pointer. saneha 1 7,734 05-02-2011, 06:47 PM
Last Post: Vuhelper
  this pointer in c++ saneha 1 2,429 05-02-2011, 06:41 PM
Last Post: Vuhelper
  Dangling pointer memory leakage Data operations saneha 0 2,522 05-02-2011, 05:43 PM
Last Post: saneha
  In aggregation we use a pointer e.g. like chair object in a room class saneha 1 2,569 05-02-2011, 04:48 PM
Last Post: Vuhelper
  const. pointer or pointer to const. char saneha 1 2,759 04-29-2011, 08:47 AM
Last Post: Vuhelper

Forum Jump:


Users browsing this thread: 1 Guest(s)
VU Help • House Banner VU Help Virtual University Students - Assignments, Solved Papers, GDB & Exam Help Student Help Forum • Collaborative • Free Support