다음은 두 변수를 교환하는 예입니다.
예시
#include <stdio.h>
int main() {
int a,b;
printf("Enter the value of a : ");
scanf("%d", &a);
printf("\nEnter the value of b : ");
scanf("%d", &b);
a += b -= a = b - a;
printf("\nAfter Swapping : %d\t%d", a, b);
return 0;
} 출력
Enter the value of a : 23 Enter the value of b : 43 After Swapping : 4323
위의 프로그램에서 두 개의 변수 a와 b는 런타임에 동적으로 선언되고 초기화됩니다.
int a,b;
printf("Enter the value of a : ");
scanf("%d", &a);
printf("\nEnter the value of b : ");
scanf("%d", &b); 세 번째 변수를 사용하지 않고 숫자가 바뀝니다.
a += b -= a = b - a;