r/learnprogramming • • 17m ago

PROTIP

If your C program "works sometimes and crashes other times," it's almost always undefined behavior — uninitialized variable, off-by-one on an array, or using memory after free. Run it with valgrind, it literally tells you the line. Changed my life in first year.

3 Upvotes

1 comment sorted by

•

u/TheOddHurricane 6m ago

Valgrind was one of those tools where I just sat there staring at the output thinking about all the hours I'd wasted before knowing it existed. Feels like cheating honestly.