Write a function that returns a pointer to a number changes
Write a function that returns a pointer to a number, changes its value randomly (using a random number generator) and then returns the pointer of the modified number. Show program in C++
Solution
main.cpp
#include <iostream>
using namespace std;
int * getRandom( ) {
static int p[10];
for (int i = 0; i < 10; ++i) {
p[i] = rand();
cout << p[i] << endl;
}
return p;
}
int main () {
int *m;
m = getRandom();
for ( int i = 0; i < 10; i++ ) {
cout << \"*(m + \" << i << \") : \";
cout << *(m + i) << endl;
}
return 0;
}
Output :
