Should be 7 in ASCII the output?
#include <bits/stdc++.h>
using namespace std;
int main() {
char a = '7';
int b = 7;
cout << (char)b;
}
Should be 7 in ASCII the output?
#include <bits/stdc++.h>
using namespace std;
int main() {
char a = '7';
int b = 7;
cout << (char)b;
}
Clearly not, because the ASCII code for '7' is 0x37 (55). ASCII 7 is the BEL control character. If supported by the particular environment you run it on, it will issue some alert sound or beep.
In this case the cast causes std::ostream::operator<<(char)
rather then std::ostream::operator<<(int)
to be called, emitting the character BEL ('\a'
or 7) to be emitted rather then presenting a decimal string representing the integer value 7.