You may have an uninitialized value....
- Check the warnings and notes that the compiler issues.
- debug using the -gt option (also -gtt and -gttt and -gtttt). 4 debug runs, with 1 to 4 "t".
You can also try to run in valgrind. Compile with -gv
valgrind --tool=memcheck yourapp
Note, running in valgrind is slow. Seriously slow. But often worth it.