As the title says, what kind of program is a program that outputs integer (int type) data in memory?
I want to write a program that outputs integer (int type) data in memory with c ++ and know the output result when -234 is input, but I don't know what the data in memory means.
What kind of code should I write specifically?

  • Answer # 1

    constexpr int N = sizeof (int);
    int A = -234;
    unsigned char * p = (unsigned char *) (&A);
    for (int i = 0;i<N;++ i) {printf ("% 2x", p [i]);}

    I don't know what kind of display is required,
    printf ("% p:% 2x \ n", p + i, p [i]);It may be better to do something like that.

  • Answer # 2

    Do you want to see the bit representation of -234?
    If so, you can do the following:

    bitset --cpprefjp C ++ Japanese Reference

    int main ()
        int x = -234;
        std :: string bin_repr = std :: bitsof<sizeof (x) * 8>(x) .to_string ();
        std :: cout<<bin_repr<<std :: endl;
        return 0;