I was running into this problem on my M1 Pro MacBook. A bandage is to delete the .out file before every time you compile the C/C++ file. The fix to my problem was to completely remove CommandLineTools using:
rm -rf /Library/Developer/CommandLineTools
then reinstalling xcode using
xcode-select --install
I think this problem may be caused when I moved all my files from my intel MacBook to my M1 Pro MacBook. I've been running into quite a few architecture bugs with the switch to ARM.