Wild Pointer in C++ language

Wild pointer are pointers that have not been initialized and can make a program crash or behave oddly. This is due to the fact that in the C++ programming language, pointers that are not specifically initialized point to unpredictable address in memory.

Write a C++ program in  which use of wild pointer are demonstrated.

   

#include<iostream>
using namespace std;
int main()
{
int *ptr ;
cout<<"Address on ptr is : "<< ptr;
cout<<endl;
cout<<"Value of address that is on ptr is : "<< *ptr;
return 0;
}


Explanation
: Here ptr is a wild pointer because it has not been initialized. There is a difference between the NULL pointer and wild pointer. Null pointer points the base address of segment while wild pointer doesn't point any specific memory location.

The above program output is tested on www.jdoodle.com

Output:
Address on ptr is : 0x563a1ceceadc
Value of address that is on ptr is : -443987883


Thanks
Mukesh Rajput


Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment:

0 comments: