It doesn't matter which kind of literal you are using to initialize an int
variable
int x = 0x0A;
int y = 10;
The above statements assign the exactly same value to the variables.
To output numeric values with hexadecimal base representation you can use the std::hex
I/O stream manipulator:
#include <iostream>
#include <iomanip>
int main() {
int x = 10; // equivalents to 0x0A
int y = 0x0A; // equivalents to 10
std::cout << std::setw(2) << std::setfill('0')
<< "x = " << std::hex << "0x" << x << std::endl;
std::cout << "y = " << std::dec << y << std::endl;
return 0;
}
Output:
x = 0xa
y = 10
See the live sample here.