Explore the world of `pointers` in C programming! Learn about the different types of memory pointers can refer to, including dynamic and static memory allocation. --- This video is based on the question https://stackoverflow.com/q/66931274/ asked by the user 'Fildo7525' ( https://stackoverflow.com/u/13460995/ ) and on the answer https://stackoverflow.com/a/66931362/ provided by the user 'Petr Skocik' ( https://stackoverflow.com/u/1084774/ ) at 'Stack Overflow' website. Thanks to these great users and Stackexchange community for their contributions. Visit these links for original content and any more details, such as alternate solutions, latest updates/developments on topic, comments, revision history etc. For example, the original title of the Question was: What type of memory is pointer pointing to in c? Also, Content (except music) licensed under CC BY-SA https://meta.stackexchange.com/help/l... The original Question post is licensed under the 'CC BY-SA 4.0' ( https://creativecommons.org/licenses/... ) license, and the original Answer post is licensed under the 'CC BY-SA 4.0' ( https://creativecommons.org/licenses/... ) license. If anything seems off to you, please feel free to write me at vlogize [AT] gmail [DOT] com. --- Understanding Pointers in C: Memory Types Demystified Pointers are fundamental in C programming, serving as crucial tools to handle memory efficiently. If you're trying to navigate the complexities of what type of memory pointers actually point to, you're not alone. It can be quite confusing, especially when dealing with dynamically allocated memory versus static variables. In this post, we'll break down the different types of memory in C and clarify exactly what pointers refer to. The Basics of Memory in C Before we dive into pointers, it's important to understand the two main categories of memory in C: Static Memory: This includes variables that are declared globally or with static storage duration. They are allocated at the start of the program and deallocated when the program ends, remaining in memory for the entire lifetime of the program. Dynamic Memory: This is memory that is allocated during runtime using functions such as malloc(), calloc(), or mmap(). This memory is flexible and can be allocated as needed, but it also needs to be managed properly to avoid memory leaks. What Do Pointers Point To? So, when you have a pointer in C, what type of memory does it actually point to? The answer can be a bit nuanced. Here's a breakdown: Pointers to Static Memory: When a pointer points to a variable that is statically allocated (e.g., global variables or local variables marked as static), it points directly to that memory location in the RAM. Example: [[See Video to Reveal this Text or Code Snippet]] Here, ptr points to the RAM where global_var is stored. Pointers to Dynamic Memory: When you use functions like malloc() or calloc(), the memory allocated is also stored in RAM but is handled differently. This memory is meant to be freed once it's no longer needed. Example: [[See Video to Reveal this Text or Code Snippet]] In this example, dynamic_ptr points to a dynamically allocated area in the RAM. The Role of the Operating System It's essential to understand that all of this memory—regardless of whether it's static or dynamic—is managed by the operating system (OS). The OS allocates RAM for the program to use and does so effectively by ensuring that: Static Variables: Are never returned back to the OS until the program terminates. Dynamic Variables: Can be returned to the OS using the free() or munmap() functions, but this only returns the memory to the C standard library; it's ultimately up to the library to return it to the OS. Conclusion Understanding pointers and the types of memory they point to is vital for effective C programming. Whether dealing with static or dynamic memory, remember that all of it resides in RAM. Proper memory management and allocation techniques are essential to avoid leaks and crashes in your programs. Now that you have a clearer picture of what pointers in C refer to, you're one step closer to mastering the intricacies of memory management in your coding journey! Feel free to ask any questions or share your thoughts in the comments below! Happy coding!