dimanche 2 décembre 2018

C++ How to show array element memory address in decimal (instead of hexadecimal)?

My program

#include <iostream>

using std::cout;
using std::endl;

int main() {

        int a[] = {1, 3, 5, 7, 9};

        for (int i = 0; i < n; i++) {
                int address = &a[i];
                cout << "a[" << i << "] = " << a[i] << " at address " << &a[i] << " = decimal " << address << endl;
        }

}

I want to print array element address in decimal, but above code fails to compile.

I have also tried to print it using

cout << std::dec << &a[i] << endl;

but that does not work too

Aucun commentaire:

Enregistrer un commentaire