+ 12
Please help me understand the differences between ++x, x++, --x, and x--.
16 Réponses
+ 24
Pre-increment and pre-decrement operators increments or decrements the value of the object and returns a reference to the result.
1) prefix increment (pre-increment) ==> ++ expr
2) prefix decrement (pre-decrement) ==> -- expr
Post-increment and post-decrement creates a copy of the object, increments or decrements the value of the object and returns the copy from before the increment or decrement.
1) postfix increment (post-increment) ==> expr ++
2) postfix decrement (post-decrement) ==> expr --
+ 13
++X is the prefix increment operator, this means that the value of x is first incremented and then used in the program.
X++ is postfix increment operator, this means that the value of x is first used in the program and then incremented.
--x is prefix decrement operator, this means that the value of x is first decremented and then used in the program.
x-- is postfix decrement operator, this means that the value of x is first used in the program and then decremented.
X++ and ++x are equivalent to x = x + 1
and
x-- and --x are equivalent to x = x - 1
+ 10
++x => first increase the variable and then use it
x++ => first use the variable then use it
for example:
$x = 4
echo $x++; => output = 4
$x = 4
echo ++$x; => output = 5
The same with --x and x--
(Example was with PHP)
+ 6
plz give me examples
+ 2
*first use the variable then increase it
+ 2
#include <iostream>
using namespace std;
int main() {
int x=10;
int y=10;
int z=++x;
int i=y++;
cout<<z<<endl;
cout<<i<<endl;
return 0;
}
+ 1
#include <iostream>
using namespace std;
main()
{
int a = 21;
int c ;
// Value of a will not be increased before assignment.
c = a++;
cout << "Line 1 - Value of a++ is :" << c << endl ;
// After expression value of a is increased
cout << "Line 2 - Value of a is :" << a << endl ;
// Value of a will be increased before assignment.
c = ++a; cout << "Line 3 - Value of ++a is :" << c << endl ;
return 0;
}
output::
Line 1 - Value of a++ is :21
Line 2 - Value of a is :22
Line 3 - Value of ++a is :23
+ 1
z=11, i=10
+ 1
i have one doubt what is the associativity of postfix? when two operats have the same precidence
+ 1
Good
+ 1
Yh
0
WHo can explain me this one??Why I need i ?Why 3=3/10 ,the number has 1 number, ? What happen whe 5=5/100 ?
#include <iostream>
using namespace std;
int main()
{
int n,m,i=0;
cout<<"Introduceti numarul n: ";
cin>>n;
m=n;
while (n!=0)
{
n=n/10;
i++;
}
cout<<"Numarul "<<m<<" are "<<i<<" cifre!";
}
0
(doubt time)😢
In the case of counting digits present in a given number , what will be code and explanation for it.....plzz help me out😊☺️
0
This post is really useful and helpful to know more about the things which you have shared. I appreciate you for such a great amount of information. I assure this would be beneficial for many people. https://www.dumpscafe.com/Braindumps-SY0-501.html