Re: [Dev-C++] Pos and Pre Incremental/Decremental Operators Examples
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Per W. <pw...@ia...> - 2003-05-13 03:27:12
|
Example 2 - you forget about the execution order of for statement.
for (i=3D0; i < 10; i++) cout << i;
is similar to
i =3D 0;
while (i < 10) {
cout << i;
i++;
}
so obviously, changing i++ to ++i doesn't change function. For a change,
insted test:
i =3D 0;
while (i++ < 10) {
cou << i;
}
which becomse
for (i =3D 0; i++ < 10;) cout << i;
Now, i++ or ++i does matter.
/Per W
On Mon, 12 May 2003, Andr=E9 Mac=E1rio Barros wrote:
> Dear Users:
>
> Please consider the following examples:
>
> Example 1:
> ...
> int c;
> c=3D0;
> cout << c++; ---> it will print 0;
> cout << c; ---> it will print 1;
> c=3D0;
> cout << ++c; ---> it will print 1;
> cout << c; ---> it will print 1;
> ...
>
> Example 2:
> ...
> 1-int i;
> 2-for(i=3D0; i<10; i++) cout << i; ---> it will print 0 to 9
> 3-for(i=3D0; i<10; ++i) cout << i; ---> it will print 0 to 9 (too!)
>
> Statements/Questions:
> 1-I only have example #1 style to teach pos and pre incremental operators=
;
> 2-I thought in Example 2, line 3 an output like numbers 1 to 10. Why this
> not happens?
> 3-Does anybody have good and simple examples of using pos and pre
> incremental/decremental
> operators?
>
> Regards
> Andre
>
>
>
>
> -------------------------------------------------------
> Enterprise Linux Forum Conference & Expo, June 4-6, 2003, Santa Clara
> The only event dedicated to issues related to Linux enterprise solutions
> www.enterpriselinuxforum.com
>
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
|