数组中0和0之间的差值 [英] The difference between 0 and '0' in array

查看:162
本文介绍了数组中0和0之间的差值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个关于数组初始化的问题

I have a question about array initialization

= {0};

char a [6] = {'0','0' ,'0','0','0','0'};

char a[6]={'0','0','0','0','0','0'};

编译器如何解释上述两个表达式?

How does the compiler interpret the above two expression? Are they just the same or not??

推荐答案

'0'是数字0的 ASCII 字符。其值为48。

'0' is the ASCII character for the number 0. Its value is 48.

常量 0 是一个零字节或空字节,也写成'\0'

The constant 0 is a zero byte or null byte, also written '\0'.

这四个是等价的:

char a[6] = {0};
char a[6] = {0, 0, 0, 0, 0, 0};
char a[6] = {'\0', '\0', '\0', '\0', '\0', '\0'};
char a[6] = "\0\0\0\0\0"; // sixth null byte added automatically by the compiler

这篇关于数组中0和0之间的差值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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