Why does the compiler use the "s" of function (local variable) and not the global variable? And in fact, shouldn't it show an error here? since you are declaring a variable in a function with a name that is already used previously for a global variable?
Moreover, even there's reason behind because of which it is allowing this, then how can we use the Global variable in the function when another variable with same name is already declared? Please clear, thank you!
Why does the compiler use the "s" of function (local variable) and not the global variable?
Because that's how C++ works. It is known as "shadowing" and it is expected.
And in fact, shouldn't it show an error here? since you are declaring a variable in a function with a name that is already used previously for a global variable?
No. This is not an error. This is how C++ works. If you don't want this to happen, don't write code that does this.
Moreover, even there's reason behind because of which it is allowing this, then how can we use the Global variable in the function when another variable with same name is already declared?