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?

+3


source to share


2 answers


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.

+8


source


Here's the Spanish version:



int main(void)
{
    int T=1, E=2, R=2, A=31, Q=784, L=70684, I=6590711, U=1181881,
        x[] = { T*I*E*R*R*A, Q*U*E, T*A*L };

    puts((char *) x);

    return 0;
}

      

+2


source







All Articles