samedi 1 septembre 2018

Why can't see full pointer array value after passing into a function

I am learning VC++. I am wondering why i can't see full value {99,20,14,80} in "printElements3". I could see only "arr" 0xmemory address and following by "99", the first value. Does this mean I have to pass by Reference in order to see the full array values?

Appreciate someone can help me understand this. below is my code.

 #include <iostream>

 void printElements3(int *arr, int size)
 {

  for (int i= 0 ; i < size; ++i)
  {
    std::cout << arr[i] << std::endl;
  }
 }

  int main()
  {
     int arr[4]={ 99, 20, 14, 80 };
     printElements3(arr,4);
     return 0;
  }

Aucun commentaire:

Enregistrer un commentaire