ECS 30 Lecture Notes - Lecture 8: Scanf Format String, Null Character, Segmentation Fault
Document Summary
No matter how you give a function an array, it will always be received as a pointer variable. This is regardless of how the array is passed (int* or int[]). This is necessary to explicitly pass the array size. Gcc warns when using sizeof() on a decayed array. When passing the array we are giving it a reference of the array, whenever you give the array you should give the size as well. If you return the address of the local variable a segmentation fault is likely as you will try to reference a variable that does not exist anymore. You can return variables from functions, but the memory addresses will disappear. Searching and sorting arrays are two of the most common array problems. You can use returns of different values to encode different types of information. Returning the index of the array is a good way to search something.