Does static variables have any advantage with respect to performance, over global variables? If I could use either static or global, which one should I prefer?
Use static. Not because the performance is better, but because it's best to minimize the scope of your variables. Globals pollute namespace and make code unorganized and difficult to maintain.