Hello!Code:#include <iostream> union u_type { u_type(short int a); void showchars(); short int i; char ch[2]; }; u_type::u_type(short int a) { i = a; } void u_type::showchars() { std::cout << ch[0] << " "; std::cout << ch[1] << "\n"; } int main() { u_type u(1000); u.showchars(); return 0; }
What it is? In my head non-selection. The author of the code charges the value in short int i ;. The value is inserted, this desire of the author is seen in the code, and indeed, the number gets where it would be desirable.
But char ch [2]; separately, it simply lies in the union. No number was loaded into it, no symbols were inserted into it at all.
Suddenly we print this to the console. How so? What is in it? Case values? What's going on here?
The console displays a letter or badge, like the Ukrainian letter ш, and a heart, a card suit of hearts. Where from?
Can my eyes today not see the elementary? Or I do not understand important principles?