这是一样的吗? [英] Is this the same?

查看:40
本文介绍了这是一样的吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




char a [100] ="" ;;


与...相同,

char a [100];

a [0] =''\ 0'';



Is

char a[100] = "";

the same as,

char a[100];
a[0] = ''\0'';

?

推荐答案

Wat< we **** @ hotmail.com>写道:
Wat <we****@hotmail.com> wrote:

char a [100] ="" ;;

char a相同[100];
a [0] =''\ 0'';
Is char a[100] = ""; the same as, char a[100];
a[0] = ''\0''; ?



如果`a''是一个静态对象 - 是的(有些静态对象是自动地将
初始化为零)。 br />

如果'a''是自动对象 - 没有。在初始化时,如果初始化了一些

成员,则所有剩余的成员都被初始化为
为零。如果没有明确初始化 - 整个对象仍然是未初始化的




-

Stan Tobias

mailx`echo si***@FamOuS.BedBuG.pAlS.INVA LID | sed s / [[:upper:]] // g`


If `a'' is a static object - yes (sort of, static objects are automatically
initialized to zero).

If `a'' is automatic object - no. In the initialization if some
member(s) is(are) initialized, all the remaining ones are initialized
to zero. If none is explicitly initialized - the whole object remains
uninitialized.

--
Stan Tobias
mailx `echo si***@FamOuS.BedBuG.pAlS.INVALID | sed s/[[:upper:]]//g`




" S.Tobias" < SI *** @ FamOuS.BedBuG.pAlS.INVALID>在消息中写道

news:31 ************* @ individual.net ...

"S.Tobias" <si***@FamOuS.BedBuG.pAlS.INVALID> wrote in message
news:31*************@individual.net...
Wat< we **** @ hotmail.com>写道:
Wat <we****@hotmail.com> wrote:
char a [100] ="" ;;
char a[100] = "";


相同,


char a [100];
a [0] =''\ 0'';
char a[100];
a[0] = ''\0'';




如果`a''是静态对象 - 是(有些静态对象会自动初始化为零)。


If `a'' is a static object - yes (sort of, static objects are automatically
initialized to zero).




这是否由标准规定?

我有一个免费的编译器(我不会命名),它创建了PE格式的可执行文件。

当我没有初始化静态数组时,它会在.bss标题中列出数据,

所以我一直认为数据是未初始化的。 />
但是,我刚编译了以下内容并且它输出全部为零。 (并且,

如你所说,当数组在main中声明时,它不会。)


#include< stdio.h>


unsigned char s [20];


int main(无效)

{

int i;


for(i = 0; i< 20; i ++)

printf(" 0x%02X \ n" ,s [i]);


返回0;

}

如果`a''是自动对象 - 没有。在初始化中,如果某些
成员被初始化,则所有剩余的成员初始化为零。如果没有明确初始化 - 整个对象仍然未初始化。

-
Stan Tobias
mailx`echo si *** @FamOuS.BedBuG.pAlS.INVA LID | sed s / [[:upper:]] // g`



Is this mandated by the standard?
I have a free compiler ( I won''t name ) that creates PE format executables.
When I don''t initialize a static array, it lists the data in a .bss header,
so I have always assumed that the data was uninitialized.
However, I just compiled the following and it DOES output all zeros. ( And,
as you said, when the array is declared inside main, it doesn''t. )

#include <stdio.h>

unsigned char s[20];

int main (void)
{
int i;

for (i = 0; i < 20; i++)
printf ("0x%02X\n", s[i]);

return 0;
}

If `a'' is automatic object - no. In the initialization if some
member(s) is(are) initialized, all the remaining ones are initialized
to zero. If none is explicitly initialized - the whole object remains
uninitialized.

--
Stan Tobias
mailx `echo si***@FamOuS.BedBuG.pAlS.INVALID | sed s/[[:upper:]]//g`



Wat写道:


char a [100] ="" ;;

相同,

char a [100];
a [0] =' '\ 0'';

Is

char a[100] = "";

the same as,

char a[100];
a[0] = ''\0'';

?




编号前者用零初始化整个数组。后者设置

第一个元素为零,但其余元素保持不变。


-

祝你好运,

Andrey Tarasevich



No. The former initializes the whole array with zeroes. The latter sets
the first element to zero, but the rest remains unchanged.

--
Best regards,
Andrey Tarasevich


这篇关于这是一样的吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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