Using define macro and its value in quotes

Answer 1: Technically, you can define it the way you have shown, but at times, it makes sense to make the parameters which are likely to change (like hostname, username) as environment variables, and read them during the program execution. This makes your program more robust against frequent changes. The parameters which are to remain same, can surely be used as a #define preprocessor (like tablename).

A sample can be found here.

Answer 2: No, you cannot use it like that. However, since pre-processor MACROS are compile time substitution, you can take advantage of string concatenation, like

mysql_query(con, "SELECT * FROM " DB_TABLE);

where DB_TABLE is defined as a MACRO.


Is it a good idea to store host, user etc in preprocessor macros?

It is common practise, at least if the values can be considered constant in the context of the program.

Alternatively you can define constants by doing:

const char * db_host = "localhost";

The drawback here is that the simple concatenation as shown below won't work.

Can I use DB_TABLE's value inside a quoted string?

No, but you can just do:

mysql_query(con, "SELECT * FROM " DB_TABLE);