Adam Monsen

May 1, 2008

Mayday Programming Brain Teaser

Filed under: Default — Tags: , , — adam @ 7:18 am PDT

Thanks to Sam for the idea.

int k = 0;
k = k++;

After both lines execute, what is k equal to?

Apparently, the answer depends on a number of things. In Java, k is 0. In C, it may be 0 or 1 depending on your compiler!

Bonus points if you can explain why.

Powered by WordPress