Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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).
- You can’t return “int[]”. 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.
- int* fillArr(int arr[]) , would return a pointer to an array.
- then, in main
- …
- int *a = fillArr(anotherArray);
- cout << a[0] << endl;
- See? But not the other way.
- int x[5] = {1,2,3,4,5};
- x = fillArr(anotherArray); //THIS WON’T WORK.
- 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).
- You can not assign an array of size X-N to an array of size X.
- You can not assign an array of size X+N to an array of size X.
- You can not create an uninitialized array. => int arr[];
- Hope this helps.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement