c - 如何在c中将unsigned char *转换为unsigned int *?

标签 c

我想将 unsigned char * 变量转换为 unsigned int *。像这样的事情

unsigned char *test = 0;
unsigned int *x = test;

最佳答案

使用强制转换,这在 C 中是

unsigned int *x = (unsigned int*)test;

但请记住,这在您的示例中(以及我能想到的任何其他示例)中是没有用的,因为取消引用指针会给您 1、3 或 7 个字节的未定义内存。

如果您想将char提升为unsigned int,那么您必须将其存储为unsigned int在第一个放置或复制到堆栈上。

关于c - 如何在c中将unsigned char *转换为unsigned int *?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36165689/

相关文章:

char转二进制突然出错了?

将Excel公式转换为C?

c - 在C中读取二维char数组

c - 以 "int x[][n]"作为参数的函数

c++ - 通过 DEBUG 标志允许 printf

c - TextOut() 和 Shift-JIS(日语字符)

c - C 编译器中的常量折叠有多有效?

c - strrchr() 只会改变干草堆并忽略针,并且不会返回任何内容

c++ - 优化具有不规则内存访问的 CUDA 内核

c++ - 不能在嵌套结构中使用 union 元素作为 scanf() 的参数来存储所需的值