What are Wild Pointers in C/C++?


Pointers store the memory addresses. Wild pointers are different from pointers i.e. they also store the memory addresses but point the unallocated memory or data value which has been deallocated. Such pointers are known as wild pointers.

A pointer behaves like a wild pointer when it is declared but not initialized. That is why, they point any random memory location.

Here is an example of wild pointers in C++ language,

Example

 Live Demo

#include <bits/stdc++.h>
using namespace std;
int main() {
   int *arr;
   for(int i=0; i<5 ; i++)
   cout << arr[i] << " ";
   return 0;
}

Output

1 0 -426634956 32764 0

In the above program, a pointer arr is declared but not initialized. So, it is displaying some random memory locations.

int *arr;
for(int i=0; i<5 ; i++)
cout << arr[i] << " ";

karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know

Updated on: 26-Jun-2020

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements