Im a little puzzled about this behaviour. Can Anyone Explain
void Decrement(int* x){
*x--; //using this line, the output is 5
//*x=*x-1; //using this l ine, the output is 4
}
int main(){
int myInt=5;
Decrement(&myInt);
cout<<myInt<<endl;
return 0;
}
Output: 5
*x--means*(x--). That is, your program modifiesx, not what it points to. Since it’s passed by value, that modification has no effect inmain(). To match your commented line, you’d need to use(*x)--.