Day#46 'C' Coding Challenge

Day#46 'C' Coding Challenge

What is Wild pointer in C? Explain with an example.

A pointer which is not initialized is called a Wild Pointer. If the pointer is not initialized, it might point to a random location which might not even be a valid address range. The pointer shall be pointing to a garbage value.

Pointers must be initialized with NULL or assigned based on requirement. Let us consider below code to explain about Wild Pointer.

#include<stdio.h>
void main()
{
    char *ptr;
}

In the above code, ptr is a wild pointer and can point to any arbitrary value.

#include<stdio.h>
void main()
{
    char *ptr;
    char p;
    ptr = &p;
}

In the above code, ptr is no more a Wild pointer as it is assigned address of character variable p.

The same explanation can be accessed from the below video:

Post a Comment

0 Comments