S
S
sabn1k2016-02-13 14:50:32
C++ / C#
sabn1k, 2016-02-13 14:50:32

A function that returns an array. How to display all elements of an array?

typedef size_t sz;
int* array(sz n)
{
  int *arr = new int[n];
  for (sz i = 0; i < n; i++)
  {	
    cin >> arr[n];
  }
  return arr;
}
int main()
{
  setlocale(LC_ALL, "Russian");
  array(7);
  getch();
  return 0;
}

I want to display the elements of the array after the program is executed in order to understand how it works. How to do it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
AtomKrieg, 2016-02-13
@AtomKrieg

auto arr =  array(7);
for (sz i = 0; i < 7; i++)
  {	
    cout<< arr[i] << " ";
  }
delete[] arr;
system("pause");
  return 0;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question