int (*nVar)[10]..This is the variable i used in a function.. i
tried ...nothing worked.. anyone please tell me how to return it....
Show minimum, compileable code please.
We don't know if what you have is a local array and a dangling
pointer.
Prefer const references. Prefer std::vector<> over fixed arrays.
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
template< typename T >
void foo( const std::vector< T >& r_v )
{
std::copy( r_v.begin(),
r_v.end(),
std:
stream_iterator< T >(std::cout, " ") );
std::cout << std::endl;
}
int main()
{
std::vector< int > vn(10, 99);
foo( vn );
}
/*
99 99 99 99 99 99 99 99 99 99
*/
The above should really be an operator<<
If you prefer working with dumb fixed arrays:
template< typename T, const std::size_t Size >
void bar( const T (& r_a)[ Size ] )
{
for( std::size_t i = 0; i < Size; ++i)
{
std::cout << r_a
;
std::cout << " ";
}
std::cout << std::endl;
}
int main()
{
int array[10] = { 0 };
bar( array );
}
/*
0 0 0 0 0 0 0 0 0 0
*/