5examples of each increment and decrement operators.please it's urgent
Answers
Answered by
1
Increment or decrement operators are of 2 types- pre and post.
A post increment or decrement operator uses the principle of 'use then change' (returns the value first then it increases or decreases) while a pre increment or decrement operator uses the principle of 'change then use'( increases or decrease the value after which the value is returned)
For example:
int x =1;
++x;
System.out.print(x +" " );
output = 2
int x=1;
x++;
System.out.print(x +" " );
output = 1; ( the value increases after returning the value)
int x=4;
x--;
System.out.print(x +" " );
output = 4 (the value decreases after returning)
int x=4;
--x;
System.out.print(x +" " );
output = 3
A post increment or decrement operator uses the principle of 'use then change' (returns the value first then it increases or decreases) while a pre increment or decrement operator uses the principle of 'change then use'( increases or decrease the value after which the value is returned)
For example:
int x =1;
++x;
System.out.print(x +" " );
output = 2
int x=1;
x++;
System.out.print(x +" " );
output = 1; ( the value increases after returning the value)
int x=4;
x--;
System.out.print(x +" " );
output = 4 (the value decreases after returning)
int x=4;
--x;
System.out.print(x +" " );
output = 3
rashi61:
thank you so much
Similar questions
Chemistry,
8 months ago
Social Sciences,
8 months ago
Chemistry,
8 months ago
Math,
1 year ago
Science,
1 year ago