The Gateway to Computer Science Excellence
0 votes
133 views

is it dangling pointer ?

int main(void) {
      int* p;
printf("%d",*p);
    return 0;
}
 

https://ideone.com/IN77el

in Programming by Boss (10.6k points)
edited by | 133 views
0
yes, since the pointer p is only created and is not pointing to anything.
0

Why dangling? It should be uninitiated pointer. Dangling pointer is defined when the pointer was initially pointing to something and then that memory is deleted without freeing this pointer. Here, the pointer was not pointing to anything before. So should we say it as dangling pointer?

More specifically, it is a wild pointer too.

@Shaik Masthan please help here.

0

yes correct @aambazinga

pointers that do not point to a valid object of the appropriate type. I just thought this.

but dangling pointers are created after object deallocation. The pointer still points to the memory location of the deallocated memory.

0
so the answer will be uninitialized pointer.. right?
0
yes.
0
ok thanks.

1 Answer

0 votes

Wild Pointer

A pointer which is not initialized with any address( not even NULL) is called a wild pointer. The wild pointer is by default stored with the garbage value.

Be clear that there is difference among the NULL pointer and wild pointer. The NULL pointer is assigned with the address 0 where as wild pointer is not assigned with any address.

#include <stdio.h>

int main(void) { 
      int* p; 
printf("%d",*p); 
    // your code goes here 
    return 0; 

=> Here p is the pointer pointing nothing, stored with the garbage value

Important Points

  1. NULL vs Uninitialized pointer – An uninitialized pointer stores an undefined value. A null pointer stores a defined value, but one that is defined by the environment to not be a valid address for any member or object.
  2. NULL vs Void Pointer – Null pointer is a value, while void pointer is a type
by Active (1.5k points)

Related questions

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
50,737 questions
57,391 answers
198,591 comments
105,442 users