You will now learn a very useful trick to find out when a variable changes value.
Add a global variable int glob; before any function.
Then add for instance glob += 1 to any function.
Recompile, start gdb and type
watch glob
Run your program. It should stop when glob is modified.
It is easy to use watch for global variables but to stop when data allocated with malloc or calloc
is modified, you need to know the address of that data.
Put a breakpoint in pivot
Assuming you have a struct s with the array b, type
p &s.b[1]
That should give you the address of element one of the b array.
The address will be a hexadecimal number (base 16). Assume it is 1234567890abc0 and the
type of the element is double.
Now type
watch *(double*)0x1234567890abc0
Continue the program and see what happens.