More than one character in single quotes?
-
I accidentally printed more than one character in single quotes:
std::cout << 'abc' << std::endl; //Output: 6382179What that mean?
-
http://www.torsten-horn.de/techdocs/ascii.htm
=>
0x61 0x62 0x63
=>
6382179

edit: One situation comes in my mind where it could be useful: When you want to read a bmp-file's header, the bmp-file must always start with 'BM'. So you can read the first two bytes of the file into a "short"-variable and compare it to 'BM'
(Not a very realistic situation though, since there are lots of libraries loading bmp-files but nonetheless...)
-
Why no compile error?
-
C++??? schrieb:
Why no compile error?
Because it's valid C++ :p
-
Does it make any sence? who needs this?
-
C++??? schrieb:
Does it make any sence? who needs this?
For example, for micro-optimizations in some special cases:
bool isGetOrSet( const char* s ) { const unsigned int val = *reinterpret_cast<unsigned int*>( s ); return val=='get\0' || val=='set\0'; } ... bool yeah_its_valid = isGetOrSet( "set" );edit: Ups, endianess, write '\0teg' and '\0tes'.