Skip to main content
Post Closed as "Duplicate" by 2501, Cory Kramer, Mat c++
Formatted code
Source Link
msrd0
  • 8.5k
  • 10
  • 63
  • 95

I have a function declared like this

int * return_array(int * arr1 , int * arr2); 

and the function is defined like this

int * return_array(int * arr1, int * arr2) { int arr_sum[5]={0}; int count = 0;   do { arr_sum[count] = *(arr1+count)+*(arr2+count); count ++; } while (count<5count < 5); return (arr_sum); } 

this is how i am trying to access the returned array in the main function

 int *get_arr;  get_arr=return_array(arr1,arr2); cout cout<<"Their<< "Their sum is :" <<endl;  << endl; for (count=0;count<5;++count = 0; count < 5; ++count)  { cout cout<<*<< *(get_arr+count) <<endl; << endl; } 

the first sum is correct but the rest looks to be garbage values, what might be the cause?

I have a function declared like this

int * return_array(int * arr1 , int * arr2); 

and the function is defined like this

int * return_array(int * arr1, int * arr2) { int arr_sum[5]={0}; int count = 0; do { arr_sum[count] = *(arr1+count)+*(arr2+count); count ++; } while(count<5); return (arr_sum); } 

this is how i am trying to access the returned array in the main function

 int *get_arr;  get_arr=return_array(arr1,arr2); cout<<"Their sum is :" <<endl;  for(count=0;count<5;++ count)  { cout<<*(get_arr+count) <<endl;  } 

the first sum is correct but the rest looks to be garbage values, what might be the cause?

I have a function declared like this

int * return_array(int * arr1 , int * arr2); 

and the function is defined like this

int * return_array(int * arr1, int * arr2) { int arr_sum[5]={0}; int count = 0;   do { arr_sum[count] = *(arr1+count)+*(arr2+count); count ++; } while (count < 5); return (arr_sum); } 

this is how i am trying to access the returned array in the main function

int *get_arr; get_arr=return_array(arr1,arr2); cout << "Their sum is :" << endl; for (count = 0; count < 5; ++count) { cout << *(get_arr+count) << endl; } 

the first sum is correct but the rest looks to be garbage values, what might be the cause?

added 4 characters in body
Source Link
Scott Hunter
  • 50k
  • 12
  • 64
  • 107
formatting
Source Link
Cory Kramer
  • 118.7k
  • 19
  • 176
  • 233

I have a function declared like this

int * return_array(int * arr1 , int * arr2);

int * return_array(int * arr1 , int * arr2); 

and the function is defined like this

int * return_array(int * arr1, int * arr2) { int arr_sum[5]={0}; int count = 0; do { arr_sum[count] = *(arr1+count)+*(arr2+count); count ++; } while(count<5); return (arr_sum); } 

this is how i am trying to access the returned array in the main function

 int *get_arr; get_arr=return_array(arr1,arr2); cout<<"Their sum is :" <<endl; for(count=0;count<5;++ count) { cout<<*(get_arr+count) <<endl; } 

the first sum is correct but the rest looks to be garbage values, what might be the cause?

I have a function declared like this

int * return_array(int * arr1 , int * arr2);

and the function is defined like this

int * return_array(int * arr1, int * arr2) { int arr_sum[5]={0}; int count = 0; do { arr_sum[count] = *(arr1+count)+*(arr2+count); count ++; } while(count<5); return (arr_sum); } 

this is how i am trying to access the returned array in the main function

 int *get_arr; get_arr=return_array(arr1,arr2); cout<<"Their sum is :" <<endl; for(count=0;count<5;++ count) { cout<<*(get_arr+count) <<endl; } 

the first sum is correct but the rest looks to be garbage values, what might be the cause?

I have a function declared like this

int * return_array(int * arr1 , int * arr2); 

and the function is defined like this

int * return_array(int * arr1, int * arr2) { int arr_sum[5]={0}; int count = 0; do { arr_sum[count] = *(arr1+count)+*(arr2+count); count ++; } while(count<5); return (arr_sum); } 

this is how i am trying to access the returned array in the main function

 int *get_arr; get_arr=return_array(arr1,arr2); cout<<"Their sum is :" <<endl; for(count=0;count<5;++ count) { cout<<*(get_arr+count) <<endl; } 

the first sum is correct but the rest looks to be garbage values, what might be the cause?

added 10 characters in body
Source Link
Maroun
  • 96.3k
  • 30
  • 195
  • 249
Loading
Source Link
Samuel
  • 650
  • 3
  • 10
  • 26
Loading