Cast void pointer to integer array

前端 未结 2 1060
死守一世寂寞
死守一世寂寞 2020-12-15 05:38

I have a problem where I have a pointer to an area in memory. I would like to use this pointer to create an integer array.

Essentially this is what I have, a pointer

2条回答
  •  隐瞒了意图╮
    2020-12-15 05:59

    You can cast the pointer to unsigned int (*)[150]. It can then be used as if it is a 2D array ("as if", since behavior of sizeof is different).

    unsigned int (*array)[150] = (unsigned int (*)[150]) ptr;
    

提交回复
热议问题