将地址转换为整数是否可以?

Eig*_*ght 0 c casting

Queue queue = createQueue(); //queue to store int values
Node *node = getNode(8); 
enQueue(queue, (int)node);//storing an address in the int

..... some other statements ....

Node *root = (Node *) deQueue(queue);//typecasting an int to address
Node *left = root->left;
Run Code Online (Sandbox Code Playgroud)

在上面的代码中,队列可以存储整数值,同时在其中存储地址.它会造成任何问题吗?

什么是在int中存储地址可能有问题的情况或任何架构?

请举几个例子.

oua*_*uah 9

什么是在int中存储地址可能有问题的情况或任何架构?

指针大于a的体系结构int.也就是说,大多数64位系统.您可以使用该类型long或更好intptr_t.