What are Wild Pointers? How can we avoid? Last Updated : 30 Oct, 2023 Comments Improve Suggest changes 55 Likes Like Report Uninitialized pointers are known as wild pointers because they point to some arbitrary memory location and may cause a program to crash or behave unexpectedly. Example of Wild PointersIn the below code, p is a wild pointer. C // C program that demonstrated wild pointers int main() { /* wild pointer */ int* p; /* Some unknown memory location is being corrupted. This should never be done. */ *p = 12; } How can we avoid wild pointers?If a pointer points to a known variable then it's not a wild pointer. Example In the below program, p is a wild pointer till this points to a. C int main() { int* p; /* wild pointer */ int a = 10; /* p is not a wild pointer now*/ p = &a; /* This is fine. Value of a is changed */ *p = 12; } If we want a pointer to a value (or set of values) without having a variable for the value, we should explicitly allocate memory and put the value in the allocated memory. Example C int main() { int* p = (int*)malloc(sizeof(int)); // This is fine (assuming malloc doesn't return // NULL) *p = 12; } Comment K kartik Follow 55 Improve K kartik Follow 55 Improve Article Tags : DSA pointer Explore DSA FundamentalsLogic Building Problems 2 min read Analysis of Algorithms 1 min read Data StructuresArray Data Structure 3 min read String in Data Structure 2 min read Hashing in Data Structure 2 min read Linked List Data Structure 2 min read Stack Data Structure 2 min read Queue Data Structure 2 min read Tree Data Structure 2 min read Graph Data Structure 3 min read Trie Data Structure 15+ min read AlgorithmsSearching Algorithms 2 min read Sorting Algorithms 3 min read Introduction to Recursion 14 min read Greedy Algorithms 3 min read Graph Algorithms 3 min read Dynamic Programming or DP 3 min read Bitwise Algorithms 4 min read AdvancedSegment Tree 2 min read Binary Indexed Tree or Fenwick Tree 15 min read Square Root (Sqrt) Decomposition Algorithm 15+ min read Binary Lifting 15+ min read Geometry 2 min read Interview PreparationInterview Corner 3 min read GfG160 3 min read Practice ProblemGeeksforGeeks Practice - Leading Online Coding Platform 6 min read Problem of The Day - Develop the Habit of Coding 5 min read Like