Swapping Two Numbers Using Third Variable in C

Swapping two numbers using third variable in c. This program will help you to find how the number changes in c programming to interchange the number which are initialized before the program execute and how it prints the another value in c program

int main() 
int a, b, temp;
printf("Enter a number ");
scanf("%d", &a);
printf("Enter b number ");
scanf("%d", &b);
temp = a;
a = b;
b = temp;
printf("After swapping");
printf("\na = %d\n", a);
printf("b = %d", b);
return 0;



Enter a number 45

Enter b number 3

After swapping a = 3 b = 45

Swapping Program Using Temp Variable in C

The first variable’s value is assigned to the temp variable. The first variable’s value is then allocated to the second variable. Finally, second receives the temp (which contains the starting value of first ). The swapping operation is now complete.

Temporary Variable in C

A temporary variable is a variable in computer programming that has a brief lifetime and is used to retain data that will be removed quickly or before it can be stored in a more permanent memory location. Because it is temporary, it is normally specified as a local variable (a variable with only a local scope). Temporary variable is needed to execute swapping two numbers using third variable in c,

Address Operator in C

The (&) operator is a unary operator that returns the operand’s memory address. For example, if var is an integer variable, its address is &var. The precedence and right-to-left associativity of this operator are the same as those of the other unary operators.

In C, the Address Operator is also known as a pointer. This address operator is denoted by the symbol “&.” This & symbol is known as an ampersand. This & character is used in a unary operator.