the interviewer is wrong.
I compiled two functions with gcc-4.8.2 -O2 -S
void increment1(int *a) { *a += 1; } void increment2(int *a) { (*a)++; }
both generate exactly the same assembly
increment1: .LFB0: .cfi_startproc addl $1, (%rdi) ret .cfi_endproc .LFE0: .size increment1, .-increment1 .p2align 4,,15 .globl increment2 .type increment2, @function increment2: .LFB1: .cfi_startproc addl $1, (%rdi) ret .cfi_endproc
But in the context of a more precise technical tarm, both of them are atomic write , which means that it does not provide a MAD result. if you use the int64_t variable in a 32-bit or less processor bit environment, the 64-bit modification causes multiple writes. It cannot be atomic write without locking.
You can use the __sync_fetch_and_add(&a, 1) operation to __sync_fetch_and_add(&a, 1) increment in gcc environment.
source share