What are Wild Pointers in C/C++?

CC++Server Side Programming

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,


 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;


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] << " ";
Updated on 26-Jun-2020 08:12:20