I open my eyes. It’s . Panic sets as I prepare for the worst. I scream out for help but mid-scream a shines in to my eyes, temporarily blinding me. Instinctively, I raise my arm up to my face to block the light. As my eyes start to adjust to the light, I see the silhouette of a doll. pitch black spotlight A few seconds go by, and the doll turns it’s head towards me and said in a french accent: “ I want to play ze game... Iz i = i++ ze same aaaz i++? ” Being a 1 month old software engineering student, I think back to all of my experience to try to answer the question. That’s it, I lost. I jolt up from my bed, with my phone alarm ringing in my ears. I swipe right turn off my alarm. Fully awake, I look up at the ceiling and recuperate my thoughts about my dream. Does increment then assigns the value to ? i = i++ i i Something about the problem intrigued to dive deeper. So I leaped out of bed to my computer to get to the bottom of this enigma. I put on some and started to write a simple test. KPOP pretty self explanatory My heart jumped a beat when the program ran. i done messed up Shit, you done messed up A-aron. I had some time before I had to leave to go to school, so I decided to actually go even deeper and take a look at what exactly is going on in Assembly. I opened up the test program executable with gdb and set a breakpoint at main so the program would run until main returns then stop. (gdb) break main Then I ran the program with this new breakpoint. (gdb) run Finally, I wanted to see the assembly instructions for the current function (main) so I used the command. disassemble (gdb) disassemble That gave me this. assembly for test program Quick Assembly lesson. Immediate values are constants and prefixed by a . Like is the decimal 10 in hexadecimal. Register names are prefixed a . $ $0xa % Registers are small memory spaces in the processor of a computer that hold a single value. There are two types of registers: general registers and special registers. In our code sample, , , and are general registers, while and are special registers. %eax %edx %esi %edi %rbp %rsp The first two lines are called the function preamble. This pushes the old base pointer onto the stack to save for later. Then it copies the value of the stack pointer to the base pointer. So after first two lines, will point to the base of main’s stack frame. %rbp Skipping down a few lines, we can see that the value which is 10 in hexadecimal gets copied into using the instruction. is the same as the command but the l signifies that the operands will be a . is the same as and because the stack grows downwards, subtracting 4 from the base of the current stack frame actually accesses the current frame itself. Thats were the local variable is stored. So is being copied into the local variable . $0xa -0x4(%rbp) movl movl mov long -0x4(%rbp) %rbp + -0x4 i $0xa i The next line is where it gets interesting. The instruction is sort of like the instruction. , using syntax like , moves the contents from the source to the destination. lea mov mov mov <destination>, <source> , however, moves the address of the source to the destination. It calculates the address specified by its second operand as if it were going to load or store data from it, but instead it stores the calculated address into the register specified by its first operand. lea So the above instruction means . %edx = %rax + 1 Then on the next line we see. This moves the contents of - which is the local variable that has the value into . So this operation is stored in a another temporary register, not the original register. So the increment was done, just in another temporary register. 0x4(%rbp) i $0xa %edx Then I compared that to the second test of . i++ This added to . $0x1 i This explains why returns instead of . i = i++ i i + 1 So the crux of the problem is a problem of evaluation order. So when is compiled: i = i++ the value of gets copied to a temporary location i The temporary value is incremented and saved as a new value (not overwriting) The new value is stored in i Then returns the temporary value, which is the same as the original value i Having found the answer, I packed my things and got ready to go to school. I arrived at school just in time for our Peer Learning Day. I listened and participated as my peers started going over assignments from the previous week. Then out of nowhere I heard the question with the same french accent: Iz i = i++ ze same aaaz i++?