Ques. 1.) I was writing a code to swap two numbers using a temp variable. I don't know how this temp variable will affect the space complexity in this case. Below is the code.
public void swap(int a, int b){
int temp;
temp = a;
a = b;
b = temp;
}
Ques. 2) How does using these extra variables like temp have an affect on space complexity in any function in general code practice?
O(1).intis around four bytes on typical platforms. Looking at the space impact of the temp variable like an extreme microoptimization at best, unless you're somehow severely memory-constrained.