Temp is nothing in C programming, yes you heard it right temp is nothing. It’s not a function, variable or keyword.
So what is temp really?
Temp is a conventional variable just like var i or var a that is defined by users to store data. Temp is mostly used to store temporary variables which will be discarded as the program continues. You can use any variable instead of temp like c, z, starwars. But it’s better to use what most of the programmers are used to.
Let’s see an example. C program to swap two numbers.
#include <stdio.h>
int main()
{
int a, b, temp;
a = 2;
b = 5;
temp = a;
a=b;
b=temp;
printf("After Swapping\na = %d\nb = %d\n", a, b);
return 0;
}
The output of the program is
After Swapping
a = 5
b = 2
As you can see in the above code temp is just used to hold the value of a temporarily, once the value of temp is transferred to b there will be no need of temp variable. You can use any variables like var c still the result will be the same. Why don’t you give it a try?