The displayInOrder()
function is expecting a pointer to an the whole array. Instead, you passed a pointer to cities[5]
. This has two problems:
- It’s a pointer to a specific element, not the whole array.
- The last element of the array is
cities[4]
, so you’re accessing outside the array bounds.
You should call the function this way:
displayInOrder(cities);
There’s no need to use &
, an array variable automatically decays to a pointer when used as a function argument.
1
solved Getting a segmentation error when printing my array of strings