Code Snippets »
C/C++ Code Snippets
C++ - Declare Integer variable dynamically, print the memory addresses
By: Priya Kaushal On 23 DEC 2016
Here, we will learn how we can declare an integer variable dynamically and how to print address of declared memory block?
Consider the following program:
using namespace std;
Here we are declaring an integer pointer ptr and printing the address of ptr by using &ptr along with stored dynamically allocated memory block.
After that we are declaring memory for integer again and printing the same.
From this example - we can understand memory blocks are allocating dynamically, each time different memory blocks are storing in the pointer ptr.