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

6th Nov 2016, 6:43 PM
Alabi Oyewumi Emmanuel
Alabi Oyewumi Emmanuel - avatar
4 odpowiedzi
+ 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; }
6th Nov 2016, 7:19 PM
Shivam Jamaiwar
Shivam Jamaiwar - avatar
+ 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.
6th Nov 2016, 7:12 PM
Shivam Jamaiwar
Shivam Jamaiwar - avatar
0
pull up and dab
6th Nov 2016, 10:29 PM
the phantom coder
the phantom coder - avatar
0
syntax: for(int i=initialization;i<conditions;i++ori-- increment or decrement) {}
17th Nov 2016, 4:24 AM
Arun Vishwakarma
Arun Vishwakarma - avatar