Write a program that declares 2 integers and swap it using pointers.


Difficulty level
This exercise is mostly suitable for students
#include <stdio.h>
#include <conio.h>

void swap(int* A, int* B)
{
	int aux;
	aux=*A;
	*A=*B;
	*B=aux;
	
}
void main()
{
	int A, B;

	printf("Enter 2 intgers:");
	scanf("%d %d", &A, &B);

    	printf("\nBefore swapping : A = %d, B = %d", A, B);
	
	swap(&A,&B);

    	printf("\nAfter swapping : A = %d, B = %d", A, B);

	getch();
}

Back to the list of exercises
Looking for a more challenging exercise, try this one !!
Asymptotic Analysis 11