12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
#include <iostream> #include <ctime> #include <cstdlib> using namespace std; int *minuscontent(int *, int); int *randomize(int *, int); int main() { const int size = 5; int array[size]; int *mptr, *cptr; mptr = randomize(array, size); for (int i = 0; i < size; i++) array[i] = mptr[i]; cptr = minuscontent(array, size); for (int i = 0; i < size; i++) cout << mptr[i] << " "; cout << endl; for (int i = 0; i < size; i++) cout << cptr[i] << " "; cout << endl; delete[] mptr; delete[] cptr; mptr = 0; cptr = 0; system("PAUSE"); return 0; } int *randomize(int *ptr, int capacity) { ptr = new int[capacity]; srand(time(0)); for (int i = 0; i < capacity; i++) ptr[i] = 1 + rand() % 101; return ptr; } int *minuscontent(int *ptr2, int capacity) { for (int i = 0; i < capacity; i++) { ptr2[i] -= 1; } return ptr2; }
cptr
array