在C语言中,整数和字符值的存储

2023年 8月 27日 35.1k 0

在C语言中,整数和字符值的存储

We have used the integer and character variables many times in our program. Here we will see how they are stored in the memory.

In C the character values are also stored as integers. In the following code, we shall put 270 into a character type data. So the binary equivalent of 270 is 100001110, but takes only first 8-bits from right. So the result will be (00001110), that is 14. Then stores the value into variable a. It also gives warning for overflow.

In the next variable y, we are trying to store negative number say -130. The negative number will be stored as 2’s complemented method. So the binary of 130 is (10000010). The 2’s complemented value is 01111101 + 1 = 01111110. Here also the right most 8-bits are taken. So the result will be (01111110) = 126

Example

#include
int main() {
char x = 270;
char y = -130;
printf("The value of x is: %d

", x);
printf("The value of y is: %d", y);
}

登录后复制

输出

The value of x is: 14
The value of y is: 126

登录后复制

以上就是在C语言中,整数和字符值的存储的详细内容,更多请关注每日运维网(www.mryunwei.com)其它相关文章!

相关文章

JavaScript2024新功能:Object.groupBy、正则表达式v标志
PHP trim 函数对多字节字符的使用和限制
新函数 json_validate() 、randomizer 类扩展…20 个PHP 8.3 新特性全面解析
使用HTMX为WordPress增效:如何在不使用复杂框架的情况下增强平台功能
为React 19做准备:WordPress 6.6用户指南
如何删除WordPress中的所有评论

发布评论