+ 2

I do not understand these prefix and postfix. Especially how the postfix works. Can anyone help me

26th Feb 2017, 11:39 AM
Enrique
2 Antworten
+ 2
/* Example is best way to understand so we will go through example😂😜.. prefix and postfix are work same till you are not store it any variable, or not in conditional statement. eg. */ int a=0; int c; a++; cout<<"A = "<<a<<endl; /*it prints, A = 1 */ c=a++; /* at here the value of a is first store into variable and then increase by 1 so now value of c =1 and then a=2 done */ cout<<"C = "<<c<<" A= "<<a<<endl; /*it will print C = 1 A = 2 */ a=4; //assign new value to a c=++a; /* at here the value of a is first increase by 1 and then store into variable so now value of c = 5 and value of a = 5 ,too.*/ cout<<" C = "<< c<<endl; /* And you can copy this and check by put in on main 😂*/
26th Feb 2017, 11:56 AM
Arshit patel
Arshit patel - avatar
+ 1
a=0; b=2; cout<<(a++)*b;//outputs 0 the variable a is incremented by one after the operation a=0; b=2; cout<<(++a)*b;//outputs 2 the variable a is incremented by one before the operation
26th Feb 2017, 11:51 AM
infinity
infinity - avatar