The Gateway to Computer Science Excellence
0 votes

is it dangling pointer ?

int main(void) {
      int* p;
    return 0;

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

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.


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.

so the answer will be uninitialized pointer.. right?
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; 
    // 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
105,442 users