0 LIKES LikeUnLike
I have the following program where i swap the values of 2 variables by using pointers. Can i swap them without using the variable "temp"?Can i just use pointers to swap the values of 2 variables?.Please explain and comment. #include <iostream.h>main(){ int i, *ptr_i; int j, *ptr_j; int temp; i=7; j=11; cout<<"Value of i: "<<i<<"\n"; cout<<"Value of j: "<<j<<"\n\n"; ptr_i = &i; ptr_j = &j; temp = *ptr_i; i = *ptr_j; j = temp; cout<<"Value of i: "<<i<<"\n"; cout<<"Value of j: "<<j<<endl; system("pause"); }
Tags:
Report (0) (0) | earlier
Latest activity: earlier. This question has 2 answers.