int num = 10; int* ptr = # // ptr now holds the address of num cout << *ptr << endl; // prints the value of the variable num
int* ptr = new int[5]; // dynamically allocate an array of 5 integers for (int i = 0; i < 5; i++) { *(ptr+i) = i * 2; // set the value of each element in the array } for (int i = 0; i < 5; i++) { cout << *(ptr+i) << " "; // print out each element in the array }In this example, we declare a pointer `ptr` and dynamically allocate an array of 5 integers using the `new` keyword. We use a `for` loop to set the value of each element in the array and then another `for` loop to print out each element. These examples use standard C++ libraries and do not require any external packages or libraries.