ECS 30 Lecture 13: ESC 030 Lecture 13 - Arrays Continued
Monday, 30 April 2018
ECS 030 - Lecture 13
Arrays Continued
Passing array as arguments
-Arrays always decay into simple pointers
when passed as arguments
•Regardless of how the array is passed (int *
or int [ ])
•Only way to explicitly pass the array
-GCC warns when using sizeof() on
a"decayed" array
•decayed array - array that only has a value,
and address cannot be read since you are
referring to a pointer
-pointer has no address, it uses the
address of the variable it points to
Stack’s point of view
-Functions always
modify the original
arrays
1
Document Summary
Arrays always decay into simple pointers when passed as arguments: regardless of how the array is passed (int * or int [ ], only way to explicitly pass the array. Gcc warns when using sizeof() on adecayed array: decayed array - array that only has a value, and address cannot be read since you are referring to a pointer. Pointer has no address, it uses the address of the variable it points to. Cannot return a local array from a function: all local variables disappear when a function returns, array becomes unusable. You can write a function to search for a particular element in an array, and nd ts location in it: useful to remember how the function operates, code is provided. Initialisation by rows of columns, with extra pairs of braces: imagine it as if there are arrays inside of the arrays, indicated by a second bracket. Functions need to know the number of columns per rows.