C
cdg
Would anyone explain how to return an array that wasn`t passed from
"main" using a pointer. I'm not understanding how scope and memory are
involved in this.
However, I do know that there are two diferent ways to accomplish this
other than by pointers. One is by passing the array from "main" onto the
other functions, then just keep passing it along. And the other is to make a
it a global.
If possible, just correct the example program using a pointer.
#include <iostream>
using namespace std;
int ArrayFunctionOne();
int ArrayFunctionTwo(int []);
void main()
{
int i(0);
int array[20]={0};
array[20] = ArrayFunctionOne();
for(i=0; i<20; i++)
cout<<array<<" "<<endl;
}
int ArrayFunctionOne()
{
int i(0);
int array[20]={0};
for(i=0; i<20; i++)
array = i;
array[20] = ArrayFunctionTwo(array);
return array;
}
int ArrayFunctionTwo(int array[])
{
int i(0);
return array;
}
"main" using a pointer. I'm not understanding how scope and memory are
involved in this.
However, I do know that there are two diferent ways to accomplish this
other than by pointers. One is by passing the array from "main" onto the
other functions, then just keep passing it along. And the other is to make a
it a global.
If possible, just correct the example program using a pointer.
#include <iostream>
using namespace std;
int ArrayFunctionOne();
int ArrayFunctionTwo(int []);
void main()
{
int i(0);
int array[20]={0};
array[20] = ArrayFunctionOne();
for(i=0; i<20; i++)
cout<<array<<" "<<endl;
}
int ArrayFunctionOne()
{
int i(0);
int array[20]={0};
for(i=0; i<20; i++)
array = i;
array[20] = ArrayFunctionTwo(array);
return array;
}
int ArrayFunctionTwo(int array[])
{
int i(0);
return array;
}