我不明白这个任务...... [英] I don't understand this assignment...
问题描述
在下面的代码中,这是什么意思?
mine =(短*)0;
--------- -----
#include< iostream>
int main()
{
typedef short示例;
short * mine;
mine =(short *)0;
if(mine)
{
删除[]我的;
}
mine = new short [10];
for(int i = 0; i< 10; ++ i)
mine [i] = 0;
for(int i = 0; i< 10; ++ i)
std :: cout<<我的[i]
<< "短
<< std :: endl;
}
------------
干杯,
Deets
" Anon Email" <一个******** @ fastmail.fm>在消息中写道
news:83 ************************* @ posting.google.co m ... < blockquote class =post_quotes>在下面的代码中,这是什么意思?
我的=(短*)0;
这意味着将零转换为短指针并将其分配给我的。顺便说一下,
演员没有必要。代码中还有更多的谜团
。
--------------
#包括< iostream>
{
typedef简短示例;
好的,但没有用过。
短*我的;
我的=(短*)0;
如果(我的)
这意味着如果我的不是0.但我们当然只是设置为0,那么为什么
打扰?
{
删除[]我的;
}
我的=新短[10];
上面7行可以写成
short * mine = new short [10];
当然最好避免使用新字母。完全只是写了
我的短片[10];
这样我们就不会像我们这样做了内存泄漏代码。
for(int i = 0; i< 10; ++ i)
mine [i] = 0;
for(int i = 0; i< 10; ++ i)
std :: cout<<我的[i]
<< "短
<< std :: endl;
}
------------
干杯,
Deets
您将此称为赋值 ......你的导师写了这个吗?
< shudder>
-
Cy
http://home.rochester.rr.com/cyhome/
" Anon Email" <一个******** @ fastmail.fm>在消息中写道
news:83 ************************* @ posting.google.co m ... < blockquote class =post_quotes>在下面的代码中,这是什么意思?
我的=(短*)0;
0是写空指针的一种方法。你听说过吗?如果没有
在你最喜欢的C ++书中查找它。
演员阵容是不必要的,风格错误。
mine = 0;
非常好。
john
" ; Cy Edmunds < CE ****** @ spamless.rochester.rr.com>在消息中写道
news:gs ******************* @ twister.nyroc.rr.com ...你称之为任务。 ......你的导师写了这个吗?
< shudder>
这是一个任务,无论是谁写的:
mine =(短*)0;
DW
In the code below, what does this mean?
mine = (short *)0;
--------------
#include <iostream>
int main()
{
typedef short Example;
short *mine;
mine = (short *)0;
if(mine)
{
delete [] mine;
}
mine = new short[10];
for (int i = 0; i < 10; ++i)
mine[i] = 0;
for (int i = 0; i < 10; ++i)
std::cout << mine[i]
<< " short"
<< std::endl;
}
------------
Cheers,
Deets
"Anon Email" <an********@fastmail.fm> wrote in message
news:83*************************@posting.google.co m...In the code below, what does this mean?
mine = (short *)0;
That means to cast the zero to a short pointer and assign it to mine. The
cast is not necessary, by the way. There are many more mysteries in the code
that follows.
--------------
#include <iostream>
int main()
{
typedef short Example;
OK, but not used.
short *mine;
mine = (short *)0;
if(mine)
This means if mine is NOT 0. But of course we just set it to 0, so why
bother?
{
delete [] mine;
}
mine = new short[10];
The 7 lines above could have been written
short *mine = new short[10];
Of course it would have been better to avoid "new" altogether and just write
short mine[10];
That way we can''t have a memory leak as we do in this code.
for (int i = 0; i < 10; ++i)
mine[i] = 0;
for (int i = 0; i < 10; ++i)
std::cout << mine[i]
<< " short"
<< std::endl;
}
------------
Cheers,
Deets
You called this an "assignment" ... did your instructor write this?
<shudder>
--
Cy
http://home.rochester.rr.com/cyhome/
"Anon Email" <an********@fastmail.fm> wrote in message
news:83*************************@posting.google.co m...In the code below, what does this mean?
mine = (short *)0;
0 is one way of writing the null pointer. Have you heard of that? If not
look it up in your favourite C++ book.
The cast is unnecessary and stylistically wrong.
mine = 0;
is prefectly good.
john
"Cy Edmunds" <ce******@spamless.rochester.rr.com> wrote in message
news:gs*******************@twister.nyroc.rr.com...You called this an "assignment" ... did your instructor write this?
<shudder>
This is an assignment regardless of who wrote it:
mine = (short *)0;
DW
这篇关于我不明白这个任务......的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!