+ 3
....FOR Loops Increment and Decrement Formats...
For example=> compare these two formats int a; [ a++ , ++a a-- , --a ] and [a=a+1 , a=a-1] QUESTIONS=> # What are the differences between these two groups ? # In what situations are they best applied ? # Can both be used interchangeably ? # Will both produce same results ?
4 Answers
+ 3
Run this program you get better idea.
#include <iostream>
using namespace std;
int main() {
int a=1;
for(int i=0;i<5;i++
cout<<a++<<"\t";
cout<<"\n";
a=1;
for(int i=0;i<5;i++)
cout<<++a<<"\t";
return 0;
}
+ 1
hear
a++ 1st print the value of a and then increment by 1.
And
++a 1st increment by 1 and then print the value.
it similar for a-- And --a.
And
the answer of a++ and a=a+1 is same
and similarly a--and a=a-1.
0
pull up and dab
0
syntax:
for(int i=initialization;i<conditions;i++ori-- increment or decrement)
{}