devxlogo

Pointers’ content reset

Question:
I’ve declared a pointer to integer in file A of project. The pointer is also being used by file B of the same project. I discovered that the pointer’s value (i.e. the address which it’s pointing to) is reset to a value of NULL when it enters file B. The program is stepped thru. What can be the possible cause?

Answer:
C/C++ will not reset global variables when moving from one function to another. You must have something else happening here. My best guess is that you have actually declared the point twice, possibly by including a header file twice that declares it for both file A and B.

Charlie has over a decade of experience in website administration and technology management. As the site admin, he oversees all technical aspects of running a high-traffic online platform, ensuring optimal performance, security, and user experience.

See also  How Seasoned Architects Evaluate New Tech

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.