This topic has been archived. It cannot be replied.
-
工作学习 / IT技术讨论 / An interesting question.
-diao_david(David Diao);
2001-2-9
{1149}
(#25443@0)
-
My answer for discussion
-old(HH);
2001-2-11
{2706}
(#25614@0)
-
HH, I really appreciate your advices
-diao_david(David Diao);
2001-2-11
{1368}
(#25630@0)
-
Thank you. I am very interested in your quiz, thouth I don't know whether my answer is correct or not.
Hard work pay off. It is not easy for us to survive here. Let's make our great efforts to learn much more!
-old(HH);
2001-2-11
(#25632@0)
-
Congratulations for your new opportunity! Any experience is a part of one's life. Cherish them!
-old(HH);
2001-2-11
(#25675@0)
-
Thanks. I take this opportunity of expressing my sincere appreciation of your help to me -- a fan of computer.
-diao_david(David Diao);
2001-2-11
(#25676@0)
-
Discussion
-diao_david(David Diao);
2001-2-11
{2652}
(#25634@0)
-
My discussion
-old(HH);
2001-2-11
{1180}
(#25658@0)
-
我当时的想法就是想取个200的整,虽然我知道在C里是以0为底。如果真的想掐好时间刚好10^100年的话,用心算还真有些麻烦了。
-diao_david(David Diao);
2001-2-11
(#25665@0)
-
BTW, you ask me "Please change vals[200] to vals[199], then run it and tell me the result. " Ok, please wait! I must write this item in my will. Then my son's son's son's ... can tell you the result. :-)
-diao_david(David Diao);
2001-2-11
(#25667@0)
-
I will disappear from this world before you.
-old(HH);
2001-2-11
(#25670@0)
-
对于问题二的讨论
-diao_david(David Diao);
2001-2-11
{2067}
(#25657@0)
-
"*ptr++=0
这一行比较绕人。请注意操作符的优先顺序。是指针 ptr 先加一,然后再给 ptr 指向的地址赋零。 "
It sould be *(ptr++)=0;
-old(HH);
2001-2-11
(#25661@0)
-
我编译并且运行了这段程序。*ptr++ 可能不规范,但是它确实实现了和 *(ptr++) 同样的功能。
-diao_david(David Diao);
2001-2-11
(#25664@0)
-
It is not a problem about programming style. I think it is better for you to know the difference. Please try:int vals[200];
int * ptr;
::memset(vals, '\0', sizeof(int) * 200);
ptr = vals;
*ptr = 10;
cout << "before " << *ptr << endl;
*ptr++ = 20;
cout << "after " << *vals << " " << *ptr <<endl;
Then try:
int vals[200];
int * ptr;
::memset(vals, '\0', sizeof(int) * 200);
ptr = vals;
*ptr = 10;
cout << "before " << *ptr << endl;
*(ptr++) = 20;
cout << "after " << *vals << " " << *ptr <<endl;
-old(HH);
2001-2-11
{425}
(#25669@0)
-
I compile them with TC2.0. Just change the lines of output. The results of both programs are same. Could you tell me why?
-diao_david(David Diao);
2001-2-11
(#25673@0)
-
I am so sorry! That is my mistake. I disunderstood the meaning of ++ operator when I wrote above. *(ptr++)=0 and *ptr++=0 get the same result. It should be *++ptr=0. Sorry again!
-old(HH);
2001-2-11
(#25678@0)
-
Bingle!!! But even ptr++ is different from ++ptr, this program still can terminate. At here, ++ptr is wrong.
-diao_david(David Diao);
2001-2-11
(#25680@0)
-
I have been dizzying and confusing.
-old(HH);
2001-2-11
(#25681@0)
-
Dizzying posting.If you have changed vals[200] to vals[199] (vals[200] is an error) and keep the sentence *ptr++=0 in your original program, it seems to will not terminate ifself. I have not practised it. If you will try it, please let me know the result. If it terminte itself, I misunderstand something and I will learn some from my misunderstanding. Thank you!
-old(HH);
2001-2-11
{346}
(#25682@0)
-
I still prefer change the first 200 to 201. Cause I do not want to make two mistakes. And I tried this program to create small number such as 10^2 or 10^3, it does terminate itself.
-diao_david(David Diao);
2001-2-11
(#25685@0)
-
I have carefully read your program for 5 times again and I think I have known what does it mean. I agree with you this time that your program will terminate itself. I made some big mistakes and learn more today. I say sorry to you.
-old(HH);
2001-2-11
(#25706@0)
-
Just because these interesting puzzles, I love computer. And I am glad to have this opportunity to discuss them with you.
-diao_david(David Diao);
2001-2-11
(#25722@0)
-
I am glad to discussion with you too. Because the memory access errors, I didn't carefully read your program at the start stage. Next time I will be careful.
-old(HH);
2001-2-12
(#25759@0)
-
I have a better answer of question a): approximately (1 / 50,000,000) * 1,000,000!.
-old(HH);
2001-2-12
(#25765@0)
-
Sounds good.
-diao_david(David Diao);
2001-2-12
(#25807@0)