段错误+字符串操作 [英] Seg fault + string manipulation
问题描述
int main()
{
char * str = * Aamit;
* str =''R'';
printf("%s \ n",str);
}
它给出了segfault
为什么?????
int main ()
{
char *str = *Aamit ;
*str=''R'' ;
printf("%s \n " ,str);
}
it''s giving segfault
why ?????
推荐答案
ku ****** @ gmail.com 说:
int main()
{
char * str = * Aamit;
* str =''R'';
printf("%s \ n" ,str);
}
它给'segfault
为什么?????
int main ()
{
char *str = *Aamit ;
*str=''R'' ;
printf("%s \n " ,str);
}
it''s giving segfault
why ?????
你写的东西不编译,所以很难看出它是怎么回事的。
段错误。
-
Richard Heathfield< http://www.cpax.org.uk>
电子邮件:-http://万维网。 + rjh @
谷歌用户:< http://www.cpax.org.uk/prg/writings/googly.php>
Usenet是一个奇怪的放置" - dmr 1999年7月29日
What you have written doesn''t compile, so it''s hard to see how it could
segfault.
--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
ku ****** @ gmail。 com 写道:
int main()
{
char * str = * Aamit ;
* str =''R'';
printf("%s \ n",str);
}
它给了段错误
为什么?????
int main ()
{
char *str = *Aamit ;
*str=''R'' ;
printf("%s \n " ,str);
}
it''s giving segfault
why ?????
int main(无效)
{
char * str =" Aamit" ;
* str =''R'';
put(str);
返回0;
}
-
pete
int main(void)
{
char *str = "Aamit" ;
*str = ''R'' ;
puts(str);
return 0;
}
--
pete
ku ****** @ gmail.com 写道:
int main()
{
char * str = * Aamit;
* str =''R'';
printf ("%s \ n",str);
}
它给出了段错误
为什么?????
int main ()
{
char *str = *Aamit ;
*str=''R'' ;
printf("%s \n " ,str);
}
it''s giving segfault
why ?????
如果您打算写
char * str =" Aamit";
然后
* str =" R"
可能会写入只读内存,但肯定会调用未定义的
behavoir。
segvault是一种可能的结果。
另一个错误(导致未定义的行为)是缺少#include
< stdio.hresp。因此缺乏varadic功能的原型
printf()。
再见,Jojo
If you meant to write
char *str = "Aamit";
Then the
*str ="R";
possibly writes into read-only memory, but surely invokes undefined
behavoir.
segvault is one possible outcome of that.
Another fault (and causing undefined behavoir) is the lack of #include
<stdio.hresp. the resulting lack of a prototype for the varadic function
printf().
Bye, Jojo
这篇关于段错误+字符串操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!