Code obfuscation doesn't understand
I came across the following code
#include <stdio.h>
int main(void)
{
long long P = 1,E = 2,T = 5,A = 61,L = 251,N = 3659,R = 271173410,G = 1479296389,
x[] = { G * R * E * E * T , P * L * A * N * E * T };
puts((char*)x);
return 0;
}
The thing is, I don't quite understand how it works. This is very confusing to me. Can someone please explain this in detail?
edit: One more thing how to print "Hola mundo!" ("Hello world" in Spanish) the same?
source to share
Oh, this is fun. Obviously, you are declaring many variables long long
and one long long
2-cell array . Therefore the array consists of 16 bytes.
Given that each byte is one character ASCII
, the array represents 16 characters (while the latter is probably zero). You can see that:
G * R * E * E * T = 1479296389 * 271173410 * 2 *2 * 5 = 8022916924116329800 =
0x6F57206F6C6C6548
P * L * A * N * E * T = 1 * 251 * 61 * 3659 * 2 * 5 = 560229490 =
0x21646C72
Considering your processor is Little Endian , the in-memory representation of the array is:
48 65 6C 6C 6F 20 57 6F 72 6C 64 21 00 00 00 00
What is Hello World!\x00\x00\x00\x00
ASCII.
source to share