How do I cast a pointer to an int

后端 未结 5 2136
一向
一向 2021-02-13 21:54

I\'m trying to store the value of an address in a non pointer int variable, when I try to convert it I get the compile error \"invalid conversion from \'int*\' to \'int\'\" this

5条回答
  •  我在风中等你
    2021-02-13 22:50

    You can do this:

    int a_variable = 0;
    
    int* ptr = &a_variable;
    
    size_t ptrValue = reinterpret_cast(ptr);
    

提交回复
热议问题