What will the following code print?

(x86 architecture, sizeof(int) == 4)
#include <iostream>
int main()
{
    static char str[5];
    *(int*)str = 0x34333231;
    std::cout << str;
}
Explanation
1. What are the symbols:
0x31 - code of the '1'
symbol ...
0x34 - code of the '4'
symbol
2. Byte order Little-Endian - the lower byte has a smaller address.
3. The last character will be 0 because static variables are always initialized with zeros.

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Cosmo
Sign Up Now
or Subscribe for future quizzes