![]() |
In C++, local variables are those variables that are declared inside a function or a block. Generally, we cannot access these variables outside its scope using the variable name but there are some exploits that we can use to do that. In this article, we will see how to access a local variable memory outside its function or scope. Access Local Variable Outside its Scope in C++We can access the local variable memory by simply setting a pointer to the local variable memory and then accessing this pointer from outside of its scope. C++
Output
Address of local variable: 0x7ffcd9e40444 Accessing Memory of Local Variable Outside the Scope Value at 0x7ffcd9e40444: 20 But accessing local variable is not recommended as it may cause segematation faults or other undefined errors as we are accessing memory which we do not have ownership of. |
Reffered: https://www.geeksforgeeks.org
C++ |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 12 |