For example, I have:
char query[512];
declared about 27 times in my application which connects to a mysql database.
The same size each time, and declared in many different functions.
This application will never use threads.
The query is ALWAYS executed immediately after the query is set with snprintf.
There is no function in between the setting and the execution of the query to mess it up.
Are their any benefits or performance gains to declaring this as a global variable?
Absolutely, in terms of memory consumed. Each object will consume a number of bytes, meaning you could potentially use 27 times less memory for that particular variable. Additionally, there would be a small amount of overhead for creating those objects. Overall, this will not make a significant difference, but it is best practice to reuse in this sort of scenario.