If you want to see the asm you can use
objdump -d -M intel binary_name
Then you'll search for the .text
section and then the main
function.
Here is what I got on my computer using int arr[2]
and a simple printf
to use the variables.
Optimized output, compiled with -O3
mov ecx,0x2a
mov edx,0x2a
Not optimized
For this code:
arr[0] = 42;
arr[1] = 42;
The output is:
mov DWORD PTR [rbp-0x10],0x2a
mov DWORD PTR [rbp-0xc],0x2a
And for this code:
arr[0] = arr[1] = 42;
The output is:
mov DWORD PTR [rbp-0xc],0x2a
mov eax,DWORD PTR [rbp-0xc]
mov DWORD PTR [rbp-0x10],eax
In the second case there is an additional operation.
So with an optimized compilation, there is no difference, but for code readability I would not write it this way.