I'm new to C++. I was wondering why I get A2105376B
when I run the following code:
#include <iostream>
int main(){
std::cout <<'A' << ' ' <<'B'<<std::endl;
return 0;
}
Thanks in advance!
I'm new to C++. I was wondering why I get A2105376B
when I run the following code:
#include <iostream>
int main(){
std::cout <<'A' << ' ' <<'B'<<std::endl;
return 0;
}
Thanks in advance!
This ' '
is a multicharacter character literal that has the type int and an implementation defined value.
It seems you mean one-byte character literal ' '
or a string literal " "
From the C++ Standard (2.13.3 Character literals)
2 A character literal that does not begin with u8, u, U, or L is an ordinary character literal. An ordinary character literal that contains a single c-char representable in the execution character set has type char, with value equal to the numerical value of the encoding of the c-char in the execution character set. An ordinary character literal that contains more than one c-char is a multicharacter literal. A multicharacter literal, or an ordinary character literal containing a single c-char not representable in the xecution character set, is conditionally-supported, has type int, and has an implementation-defined value.
Here is a demonstrative program that outputs an integer object if it is initialized by ASCII values of three spaces.
#include <iostream>
int main()
{
int x= 0x202020;
std::cout << x << '\n';
std::cout << ' ' << '\n';
return 0;
}
The program output is
2105376
2105376