Advertisement
Guest User

Arrays C++

a guest
Nov 30th, 2015
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.97 KB | None | 0 0
  1. You can’t set an array as pass by reference. It already is, as there is compiler magic that treats it like a pointer (passing by pointer is the same, data-editing wise, as passing by reference).
  2.  
  3. You can’t returnint[]”. You will return an int* if anything, or better yet, alter the value of your parameter within the function. This follows with the above compiler magic. But only one way.
  4. int* fillArr(int arr[]) , would return a pointer to an array.
  5. then, in main
  6. int *a = fillArr(anotherArray);
  7. cout << a[0] << endl;
  8.  
  9. See? But not the other way.
  10. int x[5] = {1,2,3,4,5};
  11. x = fillArr(anotherArray); //THIS WON’T WORK.
  12.  
  13. An array is not a pointer, but the compiler pours some magic sugar to help you out, and treats them as the same often (BUT NOT ALWAYS).
  14.  
  15. You can not assign an array of size X-N to an array of size X.
  16.  
  17. You can not assign an array of size X+N to an array of size X.
  18.  
  19. You can not create an uninitialized array. => int arr[];
  20.  
  21. Hope this helps.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement