How to convert int* to int

前端 未结 7 937
无人共我
无人共我 2020-12-30 01:29

Given a pointer to int, how can I obtain the actual int?

I don\'t know if this is possible or not, but can someone please advise me?

7条回答
  •  -上瘾入骨i
    2020-12-30 01:47

    int Array[10];
    
    int *ptr6 = &Array[6];
    int *ptr0 = &Array[0];
    
    uintptr_t int_adress_6  = reinterpret_cast (ptr6);
    uintptr_t int_adress_0  = reinterpret_cast (ptr0);
    
    cout << "difference of casted addrs  = " << int_adress_6 - int_adress_0 << endl;  //24 bits
    
    cout << "difference in integer = " << ptr6 - ptr0 << endl; //6
    
    

提交回复
热议问题