无符号和有符号 int 指针之间的区别 [英] Difference between unsigned and signed int pointer

查看:113
本文介绍了无符号和有符号 int 指针之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有诸如 unsigned int* 之类的东西与 int* 不同.我知道 unsigned 的值范围更大.仍然,int* 甚至不能指向任何 unsigned int 吗?

Is there anything such as an unsigned int* which is different from int*. I know that unsigned has a higher range of values. Still, can't int* even point to any unsigned int?

推荐答案

int *unsigned int * 是两种不兼容的不同指针类型.它们也是指向不兼容类型的指针.兼容类型的定义请参考C 标准 (C11) 中的第 6.2.7 节.

int * and unsigned int * are two different pointer types that are not compatible types. They are also pointers to incompatible types. For the definition of compatible types, please refer to § 6.2.7 in the C Standard (C11).

指向不兼容类型的指针意味着例如:

Being pointers to incompatible types means that for example that this:

unsigned int a = 42;

int *p = &a;  // &a is of type unsigned int *

无效(违反了赋值运算符的约束).

is not valid (the constraints of the assignment operator are violated).

这两种类型之间的另一个区别是,对于大多数其他指针类型(尽管在这里不太可能),C 不能保证它们具有相同的大小或相同的表示形式.

Another difference between the two types is as for most other pointer types (although unlikely here) there is no guarantee from C they have the same size or the same representation.

这篇关于无符号和有符号 int 指针之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆