有帮助吗? [英] Any help?

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

问题描述

有人可以帮我解决这个问题吗?我想我已经把它缩小了

到4中有2个但不确定。

char array [80] ="我很简短;

这是真的吗?数组的大小将减少到10或

数组大小保持在80并且字符串填充数组位置,从数组[0]开始是


解决方案

cj写道:

有人可以帮我解决这个问题吗?我想我已经把它缩小到4个中的2个但不确定。
char数组[80] ="我很矮;
这是真的吗?数组的大小将减少到10或者数组大小保持在80并且字符串填充数组位置,从数组[0]开始。



为什么不找出来?


#include< stdio.h>

int main(int argc,char ** argv){

char array [80] ="我很短;

printf("%lu \ n",(unsigned long)sizeof(array)); / *最佳格式

c89 * /

返回0;

}


tedu写道:

cj写道:

有人可以帮我解决这个问题吗?我想我已经把它缩小到4个中的2个但不确定。
char数组[80] ="我很矮;
这是真的吗?数组的大小将减少到10或者数组大小保持在80并且字符串填充数组位置,从数组[0]开始。


为什么不找出来?

#include< stdio.h>
int main(int argc,char ** argv){
char array [80] ="我很短;
printf("%lu \ n,(unsigned long)sizeof(array)); / *最佳格式为
c89 * /
返回0;
}




学习_why_不是更好这是如此,而不只是

展示最终答案?





char数组[80 ] ="我很短;


保留80个字节供阵列使用。这些可以任何方式填写

可以想象。它还指定了字符''我很短'',然后是从数组[0]开始的0

。其余部分未使用,但可以在需要时使用。


C中的字符数组不是字符串。 C没有字符串

类型。按照惯例(由许多标准库

函数识别)" strings"只是由零

字符终止的字符数组。文字字符串(用双引号括起来的字符串)

只是方便地表达这个而不用实际输入

终止零 - 这是隐含的。


我肯定有更好的(更多的PC?)方式这样说,但我认为

它比仅仅展示后效更有帮助。


干杯


弗拉基米尔


-

我的电子邮件地址是真实的,我读了它。


cj写道:


有人可以帮我解决这个问题吗?我想我已经把它缩小到4个中的2个但不确定。
char数组[80] ="我很矮;
这是真的吗?阵列的大小将减少到10


No.


/ * BEGIN new.c * /


#include< stdio.h>


int main(无效)

{

char数组[80] ="我很简短;


printf(" sizeof array is%u \ n",(unsigned)sizeof array);

puts(array) ;

返回0;

}


/ * END new.c * /


数组大小保持在80并且字符串填充数组位置,
从数组[0]开始。




是的,其余的字符串后面的数组元素,

初始化为零。


-

pete


Can someone help me with this question? I think I''ve narrowed it down
to 2 out of the 4 but not sure.
char array [80] = " I am short";
Which would be true? The size of the array would be reduced to 10 or
the array size stays at 80 and the string fills array locations,
starting at array [0].

解决方案

cj wrote:

Can someone help me with this question? I think I''ve narrowed it down
to 2 out of the 4 but not sure.
char array [80] = " I am short";
Which would be true? The size of the array would be reduced to 10 or
the array size stays at 80 and the string fills array locations,
starting at array [0].



why not find out?

#include <stdio.h>
int main(int argc, char **argv) {
char array [80] = " I am short";
printf("%lu\n", (unsigned long)sizeof(array)); /* best format for
c89 */
return 0;
}


tedu wrote:

cj wrote:

Can someone help me with this question? I think I''ve narrowed it down
to 2 out of the 4 but not sure.
char array [80] = " I am short";
Which would be true? The size of the array would be reduced to 10 or
the array size stays at 80 and the string fills array locations,
starting at array [0].



why not find out?

#include <stdio.h>
int main(int argc, char **argv) {
char array [80] = " I am short";
printf("%lu\n", (unsigned long)sizeof(array)); /* best format for
c89 */
return 0;
}



Wouldn''t it be better to learn _why_ this is so, instead of just
demonstrating the final answer?

The line

char array[80] = " I am short";

reserves 80 bytes for use by the array. These can be filled in any way
imaginable. It also assigns the characters '' I am short'' followed by a 0
starting with array[0]. The rest is unused, but can be if need be.

Character arrays in C are not "strings". C does not have a "string"
type. By convention (as recognised by numerous standard library
functions) "strings" are just arrays of characters terminated by a zero
character. Literal strings (the ones surrounded by double quotes) are
just convenient way to express this without actually typing the
terminating zero -- that is implied.

I''m sure there are better (more PC?) ways of saying this, but I think
it''s still more helpful than just demonstrating the after-effects.

Cheers

Vladimir

--
My e-mail address is real, and I read it.


cj wrote:


Can someone help me with this question? I think I''ve narrowed it down
to 2 out of the 4 but not sure.
char array [80] = " I am short";
Which would be true? The size of the array would be reduced to 10
No.

/* BEGIN new.c */

#include <stdio.h>

int main(void)
{
char array [80] = " I am short";

printf("sizeof array is %u\n", (unsigned) sizeof array);
puts(array);
return 0;
}

/* END new.c */
or
the array size stays at 80 and the string fills array locations,
starting at array [0].



Yes, and the rest of the array elements following the string,
are initialized to zero.

--
pete


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

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