How to convert int* to int

前端 未结 7 837
无人共我
无人共我 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条回答
  • 2020-12-30 01:59

    I'm not 100% sure if I understand what you want:

    int a=5;         // a holds 5
    int* ptr_a = &a; // pointing to variable a (that is holding 5)
    int b = *ptr_a;  // means: declare an int b and set b's 
                     // value to the value that is held by the cell ptr_a points to
    int ptr_v = (int)ptr_a; // means: take the contents of ptr_a (i.e. an adress) and
                            // interpret it as an integer
    

    Hope this helps.

    0 讨论(0)
提交回复
热议问题