Difference between null pointer and dangling pointer?
Answers were Sorted based on User's Feedback
Answer / vrushali
NULL pointer points to nothing.
But dangling pointers are those pointers which points to
invalid location (e.g. still points to those memory
locations which are already freed)
int *p = NULL;
Is mere a pointer which is not initialised to valid
memroy location. it points to nothing
int *q ;
q -> 0x1A
free (q);
still we can access this pointer using q. Still memory has
not been released to the system.
Is This Answer Correct ? | 27 Yes | 5 No |
Answer / rakshitha
Null pointer is a pointer which doesnot point to any where
in the memory location ,where as dangling pointer points to
memory location having garbage value.
Is This Answer Correct ? | 8 Yes | 1 No |
Answer / vrushali
free should be able to free as it maintains a table from
where it can start freeing the memory. It is OS related issue.
There is no way in C where we can ensure that the particular
memory is freed a even after free we can access the variable
for some time. In Java, we have a memory deallocator.
Is This Answer Correct ? | 5 Yes | 1 No |
To Sourisengupta Question.
free() shall free the memory which is allocated dynamically.
But afrer the free() function being called,the pointer
which u r passing to free() as an argument, shall point to
the same base address, which is no more valid.
Is This Answer Correct ? | 2 Yes | 0 No |
Minor correction in my ans #4...
To Sourisengupta Question.
free() shall free the memory which is allocated dynamically.
But afrer the free() function being called,the pointer
which u r passing to free() as an argument, shall point to
the same base address, which is no more valid(ie., address
is valid but no more in the allocated memory pool. It will
be added in the free memory pool).
Is This Answer Correct ? | 2 Yes | 1 No |
Answer / ravi
Both are very different.
NULL macro is
#define NULL 0
it means the macro NULL will be replaced by 0 while
preprocessing
But the NULL pointer means it points to nowhere i.e. contains 0.
It contains 0 means it may be dangerous to use such pointer
without assigning proper address to it otherwise NULL
pointer may try to access reset address may cause the
program to crash.
Is This Answer Correct ? | 0 Yes | 0 No |
Answer / sourisengupta
If free() is not able to free the memory then how we are
freeing the memory????
Is This Answer Correct ? | 4 Yes | 6 No |
Write a program to reverse a string.
0 Answers Global Logic, iNautix, TCS, Wipro,
What will be the result of the following program? char*g() { static char x[1024]; return x; } main() { char*g1="First String"; strcpy(g(),g1); g1=g(); strcpy(g1,"Second String"); printf("Answer is:%s", g()); } (A) Answer is: First String (B) Answer is: Second String (C) Run time Error/Core Dump (D) None of these
Is main is a keyword in c?
Is there a way to jump out of a function or functions?
What does 2n 4c mean?
what is structuer?
How do you determine the length of a string value that was stored in a variable?
write a c program that prints all multiples of 3between 1 and 50.
Explain this code. #include <stdio.h> void f1(int *k) { *k = *k + 10; } main ( ){ int i; i = 0; printf (" The value of i before call %d \n", i); f1 (&i); printf (" The value of i after call %d \n", i); }
Subtract Two Number Without Using Subtraction Operator
can we execute the program with the object file
differentiate between const char *a; char *const a; and char const *a;
2 Answers College School Exams Tests, HCL, TCS,