[Solved] Getting a segmentation error when printing my array of strings


The displayInOrder() function is expecting a pointer to an the whole array. Instead, you passed a pointer to cities[5]. This has two problems:

  1. It’s a pointer to a specific element, not the whole array.
  2. 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