哪里错了?怎么纠正?为什么?谢谢 [英] where wrong?how to correct?and why? thank you

查看:67
本文介绍了哪里错了?怎么纠正?为什么?谢谢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

void main()

{

char * p =" Hello";

printf("%s",p );

* p =''w'';

printf("%s",p);

}

解决方案

wwj< ww ******* @ mail2.swjtu.edu.cn>潦草地写道:

void main()


这是main()的非标准形式。无法保证它将会工作。更好用:int main(void)

{
char * p =" Hello" ;;
printf("%s",p);
* p =''w'';
printf("%s",p);
}




作业* p =' 'w''修改字符串文字,导致未定义的

行为。在大多数实现中,字符串文字驻留在只读

内存中。因此* p =''w''会导致段错或类似的事情。

请改为:char p [6] =" Hello";


-

/ - Joona Palaste(pa*****@cc.helsinki.fi)-------------芬兰------ - $ \\

\ - http:// www .helsinki.fi / ~palaste ---------------------规则! -------- /

这是一个人员通勤者。

- 科学美国人的火车司机

< br>

在文章< 87 ************************* @ posting.google.com> ,wwj写道:


缺少包含< stdio.h> ;.

void main()


int main(无效)

{
char * p =" Hello" ;;
printf("%s",p);
* p = '' W '';


你不能更改字符串文字。

printf("%s",p);


缺少刷新标准输出和返回0;。

}




更正:


#include< stdio.h>


int main(无效)

{

char p [] =" Hello";

printf("%s \ n",p);

p [0] = ''w'';

printf("%s \ n",p);

返回0;

}

-

Andreas K?h?ri


2003年11月7日06:37:44 -0800,< a href =mailto:ww ******* @ mail2.swjtu.edu.cn> ww ******* @ mail2.swjtu.edu.cn (wwj)

写道:

void main()


int main(void)!!!!!!

{
char * p =" Hello" ;;


char * p =" Hello";

不要让char *欺骗你,保留变量上的*。

printf("%s",p);


printf("%s\ n",p);

* p =''w'';


不!你不能写字符串文字,你好。

printf("%s",p);


再次,你忘记了\ n换行符。

返回0;}




void main()
{
char* p="Hello";
printf("%s",p);
*p=''w'';
printf("%s",p);
}

解决方案

wwj <ww*******@mail2.swjtu.edu.cn> scribbled the following:

void main()
This is a non-standard form of main(). There is no guarantee it will
work. Better use: int main(void)
{
char* p="Hello";
printf("%s",p);
*p=''w'';
printf("%s",p);
}



The assignment *p=''w'' modifies a string literal, causing undefined
behaviour. On most implementations, string literals reside in read-only
memory. Thus *p=''w'' can cause a segfault or something similar.
Try instead: char p[6]="Hello";

--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"This is a personnel commuter."
- Train driver in Scientific American


In article <87*************************@posting.google.com> , wwj wrote:

Missing inclusion of <stdio.h>.

void main()
int main(void)
{
char* p="Hello";
printf("%s",p);
*p=''w'';
You''re not allowed to change a string literal.
printf("%s",p);
Missing flushing of stdout and "return 0;".
}



Corrected:

#include <stdio.h>

int main(void)
{
char p[] = "Hello";
printf("%s\n", p);
p[0] = ''w'';
printf("%s\n", p);
return 0;
}
--
Andreas K?h?ri


On 7 Nov 2003 06:37:44 -0800, ww*******@mail2.swjtu.edu.cn (wwj)
wrote:

void main()
int main(void) !!!!!!
{
char* p="Hello";
char *p = "Hello";
Don''t let char* fool you, keep the * on the variable.
printf("%s",p);
printf("%s\n", p);
*p=''w'';
No! You cannot write to the string literal, "Hello".
printf("%s",p);
Again, you forgot the \n newline char.
return 0;}




这篇关于哪里错了?怎么纠正?为什么?谢谢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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