Untitled

 avatar
unknown
plain_text
2 years ago
594 B
1
Indexable
// swap function using pointer
void swapUsingPointer(int *a, int *b){
	int temp = *a;
	*a = *b;
	*b = temp;
}

//swap function using reference
void swapusingReference(int &a, int &b){
	int temp = a;
	a = b;
	b = temp;
}

int main(){	

	int a = 2;
	int b = 5;

	printf("Before Swap : a = %d, b = %d\n",a,b);

	//swap variables using pointer
	swapUsingPointer(&a,&b);//pass address of variables
	printf("After Swap : a = %d, b = %d\n",a,b);

	//swap using reference.
	swapusingReference(a,b);// just pass the values of variables
	printf("After again Swap : a = %d, b = %d\n",a,b);	

	return 0;
}