初始化字符串 [英] String initialization

查看:116
本文介绍了初始化字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是什么

之间的区别

 字符海峡[32] ='\\ 0';

 字符海峡[32] =;


解决方案

既然你已经声明的大小,两个声明是完全平等的。但是,如果不指定大小,你可以看到,第一个声明中作出较大的字符串:

 的char a [] =一个\\ 0;
炭B〔] =一个;的printf(%I%I \\ N的sizeof(A)的sizeof(B));

打印

  3 2

这是因为有两个空值(显式之一和隐式的),而仅b与隐一端。一个端

What is the difference between

char Str[32] = "\0";

and

char Str[32] = "";

解决方案

Since you already declared the sizes, the two declarations are exactly equal. However, if you do not specify the sizes, you can see that the first declaration makes a larger string:

char a[] = "a\0";
char b[] = "a";

printf("%i %i\n", sizeof(a), sizeof(b));

prints

3 2

This is because a ends with two nulls (the explicit one and the implicit one) while b ends only with the implicit one.

这篇关于初始化字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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