Binary search :lower and upper

my doubt doesnt belongs to any code ->in any function declaring local variables will destroy ,so for this reason we are using static int array,dynamic array,and using pointers in function .but int this video we are returning “ans”->which is local variable ,why it was returning without any error or something.

@Chandra123 You can’t return variables, only values. You can certainly return the value of a local variable. You can’t safely return the address of a position in memory or pointer to a local variable, because it won’t exist after the return. Here in your case you are actually returning a value which will be copied to the point where the function was called initially.