什么是无符号数据类型? [英] what is the unsigned datatype?
本文介绍了什么是无符号数据类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我见过这种 unsigned
typeless" 类型使用过几次,但从未见过对它的解释.我想有一个相应的 signed
类型.举个例子:
I've seen this unsigned
"typeless" type used a couple of times, but never seen an explanation for it. I suppose there's a corresponding signed
type. Here's an example:
static unsigned long next = 1;
/* RAND_MAX assumed to be 32767 */
int myrand(void) {
next = next * 1103515245 + 12345;
return((unsigned)(next/65536) % 32768);
}
void mysrand(unsigned seed) {
next = seed;
}
到目前为止我收集到的信息:
- 在我的系统上,sizeof(unsigned) = 4
(提示 32 位无符号整数)
- 它可能用作将另一种类型转换为未签名版本的简写:
What I have gathered so far:
- on my system, sizeof(unsigned) = 4
(hints at a 32-bit unsigned int)
- it might be used as a shorthand for casting another type to the unsigned version:
signed long int i = -42;
printf("%u
", (unsigned)i);
这是 ANSI C 还是编译器扩展?
Is this ANSI C, or just a compiler extension?
推荐答案
unsigned
实际上是 unsigned int
的简写,因此在标准 C 中定义.
unsigned
really is a shorthand for unsigned int
, and so defined in standard C.
这篇关于什么是无符号数据类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文