Hello again,
I am trying to generate an array which has random integers. Then I have to sort it and perform binary search. Below is my code so far. It gives error message (runtime check failure 2 stack around the variable num_arry was corrupted). When I define num_arry[10] instead of 9 it works. However, my array should have 10 elements but it works when defined it with 11 elements. Do you have any idea about it? Should I use reference or pointer for this task?
Thanks
#include <iostream>
#include <ctime>
using namespace std;
void generate_array(int f_array[]);
void print_array(int p_array[]);
int main()
{
int num_arry[9];
generate_array(num_arry);
print_array(num_arry);
}
void generate_array(int f_array[])
{
srand((unsigned)time(0));
for (int index = 0; index<10; index++)
{
f_array[index]=(rand()%1000)+1;
}
}
void print_array(int p_array[])
{
for(int i = 0; i<10; i++)
{
cout << "numbers " << p_array[i] << endl;
}
}