我++或++我? [英] i++ or ++i ?
问题描述
请原谅一个非常愚蠢的问题?
我已经阅读并重读了Bjarne Stroustrup,我仍然没有得到它,
所以我写这篇文章是为了帮助我理解,现在我_really_不得到它。
为什么,如果之前有一个增量,另一个之后增加,请做这些片段输出
完全相同?
#include< iostream>
int main(){
for(int i = 0; i< 10; i ++)
std :: cout<< i<<"," ;;
std: :cout<<" \ n" ;;
for(int i = 0; i< 10; ++ i)
std :: cout<< i<<"," ;;
std :: cout<<" \ n" ;;
int b = 7;
b ++; std :: cout<< b;
int c = 7;
++ c; std :: cout<<" \ n"<< c;
// ?????????为什么?相同的输出!
返回0;
}
_Same_output_。
什么是差异?
(我在一个程序中使用它们,它们不会崩溃....)
-
Peace
JB
jb@tetrahedraverse.com
网址: http://tetrahedraverse.com
Please pardon a maybe very stupid question?
I''ve read and reread Bjarne Stroustrup on this, and I still don''t "get it,"
so I wrote this to help me understand, and now I _really_ don''t "get it."
Why, if one increments before, and the other after, do these snippets output
exactly the same?
#include <iostream>
int main() {
for(int i=0; i<10; i++)
std::cout<<i<<", ";
std::cout<<"\n";
for(int i=0;i<10;++i)
std::cout<<i<<", ";
std::cout<<"\n";
int b=7;
b++; std::cout<<b;
int c=7;
++c; std::cout<<"\n"<<c;
//????????? why? same outputs!
return 0;
}
_Same_output_.
What''s the difference?
(I use these in a program, which doesn''t crash....)
--
Peace
JB
jb@tetrahedraverse.com
Web: http://tetrahedraverse.com
推荐答案
2月8日上午11:00 * am,John Brawley < jgbraw ... @ charter.netwrote:
On Feb 8, 11:00*am, "John Brawley" <jgbraw...@charter.netwrote:
请原谅一个非常愚蠢的问题?
我已阅读并重读Bjarne Stroustrup对此,我仍然没有得到它,
所以我写这篇文章是为了帮助我理解,现在我_really_不得到它。 ;
为什么,如果之前有一个增量,另一个之后增加,那么这些片段输出
完全一样吗?
#包括< iostream>
int main(){
for(int i = 0; i< 10; i ++)
std :: cout<< i<<""" ;;
std :: cout<<" \ n" ;;
for( int i = 0; i< 10; ++ i)
std :: cout<< i<<"," ;;
std :: cout< ;<" \ n" ;;
int b = 7;
b ++; std :: cout<< b;
int c = 7;
++ c; std :: cout<<" \ n"<< c;
// ????????? *为什么? *相同的输出!
返回0;
}
_Same_output_。
有什么区别?
(我在一个程序中使用它们,它们不会崩溃......)
Please pardon a maybe very stupid question?
I''ve read and reread Bjarne Stroustrup on this, and I still don''t "get it,"
so I wrote this to help me understand, and now I _really_ don''t "get it."
Why, if one increments before, and the other after, do these snippets output
exactly the same?
#include <iostream>
int main() {
for(int i=0; i<10; i++)
std::cout<<i<<", ";
std::cout<<"\n";
for(int i=0;i<10;++i)
std::cout<<i<<", ";
std::cout<<"\n";
int b=7;
b++; std::cout<<b;
int c=7;
++c; std::cout<<"\n"<<c;
//????????? *why? *same outputs!
return 0;
}
_Same_output_.
What''s the difference?
(I use these in a program, which doesn''t crash....)
试试这个,看看:
int b = 7;
std :: cout<< b ++<< endl;
int c = 7;
std :: cout<< ++ c<<结束;
-
Fred Kleinschmidt
Try this and see:
int b=7;
std::cout << b++ <<endl;
int c=7;
std::cout << ++c << endl;
--
Fred Kleinschmidt
John Brawley schrieb:
John Brawley schrieb:
请原谅一个非常愚蠢的问题?
我已经阅读并重读了Bjarne Stroustrup,我仍然没有得到它,
所以我写这篇文章是为了帮助我理解,现在我_really_不得到它。
为什么,如果之前增加,另一个增加之后,这些片段输出
完全一样吗?
#include< iostream>
int main( ){
for(int i = 0; i< 10; i ++)
std :: cout<< i<<",";
std :: cout<<" \ n" ;;
for(int i = 0; i< 10; ++ i)
std :: cout<< i<<<""" ;;
std :: cout<<" \ n" ;;
int b = 7;
b ++; std :: cout<< b;
int c = 7;
++ c; std :: cout<<" \ n"<< c;
// ?????????为什么?相同的输出!
返回0;
}
_Same_output_。
什么是差异?
(我在一个程序中使用它们,它们不会崩溃....)
Please pardon a maybe very stupid question?
I''ve read and reread Bjarne Stroustrup on this, and I still don''t "get it,"
so I wrote this to help me understand, and now I _really_ don''t "get it."
Why, if one increments before, and the other after, do these snippets output
exactly the same?
#include <iostream>
int main() {
for(int i=0; i<10; i++)
std::cout<<i<<", ";
std::cout<<"\n";
for(int i=0;i<10;++i)
std::cout<<i<<", ";
std::cout<<"\n";
int b=7;
b++; std::cout<<b;
int c=7;
++c; std::cout<<"\n"<<c;
//????????? why? same outputs!
return 0;
}
_Same_output_.
What''s the difference?
(I use these in a program, which doesn''t crash....)
也许它将帮助你定义++ i和i ++之间的区别;
这些语句也有相同的区别:
语句的值; ++ I"是i + 1
而i ++的价值是i:
#include< iostream>
using namespace std;
int main()
{
int i = 6;
cout<< ; i ++: << i ++<< ENDL; //将返回i = 6
int j = 6;
cout<< ++ i: << ++ i<< ENDL; //将返回i + 1 = 7
返回0;
}
我希望这会对你有帮助!
亲切问候,Hans
Maybe it will help you do define the difference between ++i and i++;
The statements do the same with one difference:
The value of the statement "++i" is i+1
while the value of i++ is i:
#include <iostream>
using namespace std;
int main()
{
int i=6;
cout << "i++: " << i++ << endl; //Will return i = 6
int j=6;
cout << "++i: " << ++i << endl; //Will return i+1 = 7
return 0;
}
I hope this will help you!
Kind regards, Hans
John Brawley写道:
John Brawley wrote:
Please请原谅一个非常愚蠢的问题?
我已经阅读并重读了Bjarne Stroustrup,我仍然没有得到它,
所以我写这篇文章是为了帮助我理解,现在我_really_不得到它。
为什么,如果之前有一个增量,另一个之后,做这些片段输出
完全相同?
#include< iostream>
int main(){
for(int i = 0; i< 10; i ++)
std :: cout<< i<<"," ;;
std: :cout<<" \ n" ;;
for(int i = 0; i< 10; ++ i)
std :: cout<< i<<"," ;;
std :: cout<<" \ n" ;;
int b = 7;
b ++; std :: cout<< b;
int c = 7;
++ c; std :: cout<<" \ n"<< c;
// ?????????为什么?相同的输出!
返回0;
}
_Same_output_。
什么是差异?
(我在一个程序中使用这些,它不会崩溃....)
Please pardon a maybe very stupid question?
I''ve read and reread Bjarne Stroustrup on this, and I still don''t "get it,"
so I wrote this to help me understand, and now I _really_ don''t "get it."
Why, if one increments before, and the other after, do these snippets output
exactly the same?
#include <iostream>
int main() {
for(int i=0; i<10; i++)
std::cout<<i<<", ";
std::cout<<"\n";
for(int i=0;i<10;++i)
std::cout<<i<<", ";
std::cout<<"\n";
int b=7;
b++; std::cout<<b;
int c=7;
++c; std::cout<<"\n"<<c;
//????????? why? same outputs!
return 0;
}
_Same_output_.
What''s the difference?
(I use these in a program, which doesn''t crash....)
沿着答案其他人,我的建议是,阅读一个很好的介绍
C ++书籍封面,在阅读之前阅读The C ++ Programming Language
第3版或特别版封面。
Along the answers of the others, my advice is, read a good introductory
C++ book cover to cover, before reading "The C++ Programming Language"
3rd Edition or Special Edition cover to cover.
这篇关于我++或++我?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!