....FOR Loops Increment and Decrement Formats... | Sololearn: Learn to code for FREE!


....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 ?

11/6/2016 6:43:37 PM

Alabi Oyewumi Emmanuel

4 Answers

New Answer


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; }


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.


pull up and dab


syntax: for(int i=initialization;i<conditions;i++ori-- increment or decrement) {}