空暇时候思考2('\0'等价于数字0还是字符0)
/**********************************************************************
* * Copyright (c)2015,WK Studios
* * Filename: A.h
* * Compiler: GCC vc 6.0
* * Author:WK
* * Time: 2015 6 7
* **********************************************************************/
#include<iostream>
using namespace std;
void main()
{
char a[100]={'0',48,48,0,0,'0'};
char b[]={'0',48,48,0,0,'0'};
char c[]={'0','0'};
char d[]={0};
//注意一下数字0与字符'0'差别
//'\0'等价于数字0而不是字符0
cout<<sizeof(a)<<endl;
cout<<strlen(a)<<endl;
cout<<sizeof(b)<<endl;
cout<<strlen(b)<<endl;
cout<<sizeof(c)<<endl;
cout<<strlen(c)<<endl;
cout<<sizeof(d)<<endl;
cout<<strlen(d)<<endl;
执行结果:
100
3
6
3
2
7
1
0
不行的话再看一个:
#include <iostream>
using namespace std; void example()
{
int i;
char acNew[20];
for(i = 0; i < 5; i++)
{
acNew[i] = '0' ;
}
printf("%d\n",strlen(acNew));
return ;
} void main()
{
example();
}
结果是一个随机的值,由于strlen没有找到结束的表示符‘\0’
略微修改一下:
#include <iostream>
using namespace std; void example()
{
int i;
char acNew[20];
for(i = 0; i < 5; i++)
{
acNew[i] = 0 ; // '\1' 0
}
printf("%d\n",strlen(acNew));
return ;
} void main()
{
example();
}
这次结果是0
空暇时候思考2('\0'等价于数字0还是字符0)的更多相关文章
- ivew 限制输入 0 到 1 的数字 包括小数, 0 ,1
input <FormItem label="> <Input v-model="formItem.shapeDifferen.breastScaleOutSpa ...
- Apache Tomcat/6.0.39如何配置连接mysql,JDBC:mysql-connector-java-5.1.30-bin.jar-成功连接心得
http://tomcat.apache.org/tomcat-6.0-doc/jndi-datasource-examples-howto.html 前提:开启TOMCAT,MYsql MySQL ...
- centos7中启动tomcat提示bash: tomcat8.0.39/bin/startup.sh: 权限不够
问题描述: centos7中启动tomcat提示bash: tomcat8.0.39/bin/startup.sh: 权限不够 解决方案:先进入bin目录 [root@localhost/]# cd ...
- tomcat 使用quercus-4.0.39 支持PHP
tomcat 使用quercus-4.0.39 支持PHP Quercus是Caucho公司采用纯Java开发的一个PHP5引擎.基于开源授权协议GPL发布.Quercus自带很多个PHP模块 ...
- mysql 1449 : The user specified as a definer ('root'@'%') does not exist 解决方法
权限问题,授权 给 root 全部sql 权限 mysql> grant all privileges on *.* to root@"%" identified by & ...
- 【转】 ip段/数字,如192.168.0.1/24是什么意思?
http://blog.csdn.net/aerchi/article/details/39396423 ip段/数字,如192.168.0.1/24是什么意思? ip段/数字,如192.168.0. ...
- [转帖]IP地址、子网掩码、网络号、主机号、网络地址、主机地址以及ip段/数字-如192.168.0.1/24是什么意思?
IP地址.子网掩码.网络号.主机号.网络地址.主机地址以及ip段/数字-如192.168.0.1/24是什么意思? 2016年03月26日 23:38:50 JeanCheng 阅读数:105674 ...
- 100怎么变成100.00 || undefined在数字环境下是:NaN || null在数字环境下是0 || 数组的toString()方法把每个元素变成字符串,拼在一起以逗号隔开 || 空数组转换成字符串后是什么?
100怎么变成100.00?
- paip.php 5.0 5.3 5.4 5.5 -6.0的新特性总结与比较
paip.php 5.0 5.3 5.4 5.5 -6.0的新特性总结与比较 PHP5的新特性 2 · 对象的参照过渡是默认的(default) 3 · 引入访问属性的限制 3 · 引入访问方法的限 ...
随机推荐
- (28)zabbix用户宏变量详解macro
zabbix宏变量让zabbix变得更灵活,变量可以定义在主机.模板以及全局,变量名称类似:{$MACRO},宏变量都是大写的.认识了宏变量,你会感叹zabbix越发的强大. 变量可以用于如下地方: ...
- 如何用纯 CSS 创作背景色块变换的按钮特效
效果预览 在线演示 按下右侧的"点击预览"按钮可以在当前页面预览,点击链接可以全屏预览. https://codepen.io/comehope/pen/XYKdwg 可交互视频教 ...
- C语言之结构体、联合体
结构体 1,结构体即为多个基本数据类型组合而成的数据类型.结构体本质上同int等一样同为数据类型,可以定义变量,内部成员不能直接赋值. struct Man { ; ; }; 上面是错误的.正确写法 ...
- uboot顶层mkconfig分析
GNU make:http://www.gnu.org/software/make/manual/make.html#Rules 为了便于理解把uboot中的Makefile配置部分弄出来便于理解,这 ...
- Python3的基本数据类型及常用的方法
python3的基本数据类型: 在python3当中有这么几种基本的数据类型:int(整形).str(字符串).list(列表).tuple(元组).dict(字典).bool(布尔值)等.数字整体划 ...
- 关于php使用xpath解析html中文乱码问题
$str2 = '<div id="content">我很好 </div>'; $dom = new DOMDocument(); //load之前强转字符 ...
- spring cache redis
一.使用开源包(spring-data-redis) 1.引入jar包 <dependency> <groupId>org.springframework.data& ...
- ZOJ 3469 区间DP Food Delivery
题解 #include <iostream> #include <cstdio> #include <cstring> #include <algorithm ...
- 关于Linux下安装Oracle
参考文档:http://www.cnblogs.com/gaojun/archive/2012/11/22/2783257.html 中文字符集设置: http://blog.csdn.net/ ...
- BNUOJ 1055 走迷宫2
走迷宫2 Time Limit: 1000ms Memory Limit: 65535KB 64-bit integer IO format: %lld Java class name: ...