Tracking down segmentation violations is best done with a debugger, for example gdb on Linux or lldb on macOS.
There are a few threads in the forum covering use of these, for example Using gdb debugger in an efficient way, or otherwise search for “gdb”. The easiest thing to do is simply run the program in gdb/lldb and use the bt
command, e.g.
$ gdb myProgram
... starts up
> run
... segfaults
> bt
... will print info on where the error occurred.