513 views

1 Answer

Best answer
1 votes
1 votes

After freeing up a pointer variable if we are trying to de reference that, it gives error based on the platform. Suppose we have a code snippet like this:

int a=10,*p;

p = &a;

free(p);

*p = 20;

p is a dangling pointer right.

Now this code can primarily give two kinds of error but the kind of error depends totally on the platform and implementation.(Both the errors mentioned refers to the same Error Type. The error names are different based on the platform/implementation).

  1. In case of UNIX based it will give Segmentation Fault( Core Dumped).
  2. For rest of them it usually gives ILLEGAL MEMORY ACCESS.

Again the error is totally dependent on the platform.

edited by

Related questions

3.6k
views
3 answers
5 votes
Arjun asked Feb 16
3,619 views
​​​​​What is the output of the following $\text{C}$ program?#include <stdio.h int main() { double a =20.0,25.0,* p,* q; p=a ; q=p+1 ; printf("%d,%d", (int) (q-...
495
views
2 answers
7 votes
GO Classes asked Feb 5
495 views
On a $64$-bit system, which of the following C expressions is equivalent to the C expression $(x +4)[3]?$ Assume $\mathrm{x}$ is declared as $\textsf{int}\ast \ast \text...
549
views
1 answers
1 votes
GO Classes asked Jan 21
549 views
Consider the following C program:-#include <stdio.h void ubswap(int a, int b) { int* temp = *a; *a = *b; *b = temp; } int main() { int x = 1, y = 9; int* u = &x; int* v...
456
views
1 answers
1 votes
GO Classes asked Jan 13
456 views
What will the following print:int a, b, c, *d; a = 0; b = 1 ; c = 2 ; d = & a; (*d) += b+c; d = & b; (*d) += a+b+c ; printf("a= %i b=%i\n", a, b);$a=0, b=3$$a=3, b=3$$a=3...