关于char越界的简单c
来源:互联网 发布:魔法王座升阶数据图片 编辑:程序博客网 时间:2024/05/24 15:39
结论:
1. char 有符号范围是-128~127;无符号范围是0~255;
2. 在存储媒介中,数字都是补码形式储存的(含字符常量);
3. 正数补码为本身二进制,负数补码:绝对值->取反->+1;
4. 补码的补码为源码:原码求补码是取反加1,补码求原码还是是取反加1(符号位除外) !
例子:
root@ubuntu:/mnt/temp/test_8.31# gdb test<span style="white-space:pre"></span><strong><span style="color:#ff0000;">//gdb调试</span></strong>GNU gdb (Ubuntu 7.7.1-0ubuntu5~14.04.2) 7.7.1Copyright (C) 2014 Free Software Foundation, Inc.License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>This is free software: you are free to change and redistribute it.There is NO WARRANTY, to the extent permitted by law. Type "show copying"and "show warranty" for details.This GDB was configured as "i686-linux-gnu".Type "show configuration" for configuration details.For bug reporting instructions, please see:<http://www.gnu.org/software/gdb/bugs/>.Find the GDB manual and other documentation resources online at:<http://www.gnu.org/software/gdb/documentation/>.For help, type "help".Type "apropos word" to search for commands related to "word"...Reading symbols from test...done.(gdb) list<span style="white-space:pre"></span><strong><span style="color:#ff0000;">//源码</span></strong>1#include <stdio.h>2#include <stdlib.h>34int main()5{6char a,b,c1,c2;7a = 197;8b = 198;910printf("%c,%c\n",a,b);(gdb) list11printf("%d,%d\n",a,b);12exit(EXIT_SUCCESS);13}(gdb) break 10<span style="white-space:pre"></span><span style="color:#ff0000;"><strong>//断点1为第10行</strong></span>Breakpoint 1 at 0x8048460: file test.c, line 10.(gdb) break 11<span style="white-space:pre"></span><strong><span style="color:#ff0000;">//断点2为第11行</span></strong>Breakpoint 2 at 0x804847e: file test.c, line 11.(gdb) r<span style="white-space:pre"></span>//运行Starting program: /mnt/temp/test_8.31/test Breakpoint 1, main () at test.c:1010printf("%c,%c\n",a,b);(gdb) cont<span style="white-space:pre"></span><strong><span style="color:#ff0000;">//断点1运行结果</span></strong><span style="white-space:pre"></span>Continuing.�,Breakpoint 2, main () at test.c:1111printf("%d,%d\n",a,b);(gdb) cont<span style="white-space:pre"></span><strong><span style="color:#ff0000;">//断点2运行结果</span></strong>Continuing.-59,-58<span style="white-space:pre"></span><span style="color:#ff0000;">//197 的补码是11000101,最高位是1,所以是负数,剩1000101(补码),求源码为111011,为59,加符号位"1",就是-59</span>[Inferior 1 (process 19127) exited normally]
0 0
- 关于char越界的简单c
- 关于 字符串的赋值 char *strcpy(char *dest ,char *src) 中越界问题
- 关于越界的问题
- C基础 内存越界和内存监测的简单处理
- 关于C语言的函数调用过程和数组越界
- 关于C语言,字符数组中越界的两个问题
- 关于C语言数组越界的演示程序
- 关于c语言三位八进制数越界的探讨
- 关于下标越界的问题
- 关于数组的越界问题
- 关于内存越界的问题
- 关于向量越界的问题
- C语言关于简单的字符串移位函数void LoopMove(char *pStr, int steps)
- 转载关于char的c语言指针问题:char **s char *a [ ] char a [ ]
- C语言的越界访问
- 关于2147217913 从 char 数据类型到 datetime 数据类型的转换导致 datetime 值越界 的问题解决方法
- 关于C语言char *指向的字符串
- c++ 关于char *的…
- C# 启动控制台直接打开一个网站
- HDU 5117(简单背包dp)
- 在需求分析中就可以避免的那些错误9
- XMPP协议原理及相关信息。
- Python模拟登陆大连交通大学教务在线
- 关于char越界的简单c
- iOS中uiimage和uicolor相互转化
- 设计模式: 自己手动写一个状态模式
- Spring常见面试题目
- hdu-5385
- MySQL互为主从复制以及主主互备
- WM_CLOSE、WM_DESTROY、WM_QUIT区别
- 免费的java(jsp)虚拟主机jhost
- B树的基本例程(1)插入