Redian新闻
>
这个为啥是undefined behavior?
avatar
这个为啥是undefined behavior?# JobHunting - 待字闺中
l*r
1
void f(void)
{
char * p = "wikipedia";
p[0] = 'W'; // undefined behaviour
}
avatar
g*u
2
because we can not modify the content by using this pointer p; In fact, p is
pointing a constant string. and it is stored in data segment if I remember
right.
if you want to change the value, you will define if char [] p="....";
avatar
t*t
3
c/c++ 里面
char a[] 和 char* b
其中a,b虽然很像,但是不一样
不知道为什么
avatar
b*y
4
the string is stored in the program code segmentation, which can't be
modified.

【在 l*********r 的大作中提到】
: void f(void)
: {
: char * p = "wikipedia";
: p[0] = 'W'; // undefined behaviour
: }

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。