I'm trying to print the address(reference) of a variable in hex and that too in upper case. But I see that I'm able to print the hex equivalent of 77 in upper case, but not the address(reference) of a variable. Can somebody help me please?
The following is the program I have the difficulty with.
#include <iostream>
#include <string>
using namespace std;
void print_nb_of_items(const int nb_of_apple, const int& nb_of_pens)
{
cout << "Number of apples = " << nb_of_apple << endl;
cout << "Number of pens = " << nb_of_pens << " Address = " << uppercase << hex << &nb_of_pens << endl;
cout << "Hex output in uppercase = " << uppercase << hex << 77 << endl;
}
/* The main function */
int main(int argc, char * argv[])
{
int nb_apple = 24;
int nb_pens = 65;
print_nb_of_items(nb_apple, nb_pens);
return 0;
}
The output for the program I got is:
Number of apples = 24
Number of pens = 65 Address = 0xbffbd438
Hex output in uppercase = 4D
I want the address to be printed as: 0xBFFBD438. How do I do that?