Arrays easy question
Could you write the code below using the heap?
Enter the size of the array: 5
[0] -> 0x10811f0
[1] -> 0x1081200
[2] -> 0x1081210
[3] -> 0x1081220
[4] -> 0x1081230
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
|
// Example program
#include <iostream>
#include <iomanip>
/*
[0] -> 0x10811f0
[1] -> 0x1081200
[2] -> 0x1081210
[3] -> 0x1081220
[4] -> 0x1081230
*/
int main()
{
std::cout << "Enter the size of the array: ";
int* psize = new int; // uses heap
std::cin >> *psize;
std::cout << "\n";
int start = 0x10811f0;
int step = 0x10;
for (int i = 0; i < *psize; i++)
{
std::cout << "[" << i << "] -> ";
std::cout << std::hex << start + i * step << "\n";
}
delete psize;
}
|
Enter the size of the array: 5
[0] -> 10811f0
[1] -> 1081200
[2] -> 1081210
[3] -> 1081220
[4] -> 1081230 |
Last edited on
OMG! Thank you dude!
Topic archived. No new replies allowed.