该代码是有效的吗? [英] is that code is valid?

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

问题描述

void st(const char * a)

{

cout<< a;

删除(a);

}


int main()

{

char foo [] =" CPP";


st(foo);

cout<< " \\\
\\\
" << foo;


系统(PAUSE);

返回0;

}


特别是在函数st中我使用删除(a)


也是删除foo不仅仅是一个

void st(const char *a)
{
cout << a;
delete(a);
}

int main ()
{
char foo[]= "CPP";

st(foo);
cout << "\n\n" << foo;

system("PAUSE");
return 0;
}

particular in the function st when i use delete(a)

is that also delete foo not only a

推荐答案

Virtual_X写道:
Virtual_X wrote:

void st(const char * a)

{

cout<< a;

删除(a);

}


int main()

{

char foo [] =" CPP";


st(foo);

cout<< " \\\
\\\
" << foo;


系统(PAUSE);

返回0;

}

当我使用删除时,
特别在函数st中(a)


也是删除foo而不仅仅是
void st(const char *a)
{
cout << a;
delete(a);
}

int main ()
{
char foo[]= "CPP";

st(foo);
cout << "\n\n" << foo;

system("PAUSE");
return 0;
}

particular in the function st when i use delete(a)

is that also delete foo not only a



代码无效。使用delete仅用于分配new的内存。

删除其他内容会导致崩溃。


如果有什么你不明白尝试询问一个关于它的问题

而不是显示一些疯狂的混合代码。


-

Scott McPhillips [MVP VC ++ ]

The code is not valid. Use delete only for memory allocated with new.
Deleting something else will lead to a crash.

If there''s something you don''t understand try asking a question about it
instead of showing some crazy mixed up code.

--
Scott McPhillips [MVP VC++]


" Scott McPhillips [MVP]" < org-dot-mvps-at-scottmcpwrote:
"Scott McPhillips [MVP]" <org-dot-mvps-at-scottmcpwrote:

Virtual_X写道:
Virtual_X wrote:

> void st(const char * a)
{
cout<< a;
删除(a);
}
int main()
{char / foo [] =" CPP" ;;

st(foo);
cout<< " \\\
\\\
" << foo;

系统(PAUSE);
返回0;
}

特别是在我使用delete时的函数st(a)

也是删除foo不仅
>void st(const char *a)
{
cout << a;
delete(a);
}

int main ()
{
char foo[]= "CPP";

st(foo);
cout << "\n\n" << foo;

system("PAUSE");
return 0;
}

particular in the function st when i use delete(a)

is that also delete foo not only a



代码无效。


The code is not valid.



更确切地说:它有未定义的行为。

To be more precise: It has undefined behavior.


Virtual_X写道:
Virtual_X wrote:

void st(const char * a)

{

cout<< a;

删除(a);

}


int main()

{

char foo [] =" CPP";


st(foo);

cout<< " \\\
\\\
" << foo;


系统(PAUSE);

返回0;

}

当我使用删除时,
特别在函数st中(a)


也是删除foo而不仅仅是
void st(const char *a)
{
cout << a;
delete(a);
}

int main ()
{
char foo[]= "CPP";

st(foo);
cout << "\n\n" << foo;

system("PAUSE");
return 0;
}

particular in the function st when i use delete(a)

is that also delete foo not only a



昨天,Jim Langston告诉你:


删除只应该在分配有new的内存上使用,使用delete []

with new []

如果你不想听听别人的话,那就不要浪费时间了。

每个人的时间。


Brian

Yesterday, Jim Langston told you:

"delete should only be used on memory allocated with new, use delete[]
with new[]"
If you aren''t going to LISTEN to what people you, then stop wasting
everyone''s time.

Brian


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

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