user8842434
user8842434

Reputation:

Can I use string for constant part of #define?

Can I use string for constant part of #define like this?

#define A string

if I can't, what can be alternative?

Upvotes: 0

Views: 48

Answers (1)

Yes, you can. For instance,

#define MY_PATH "/path/to/file"

That defines a macro named MY_PATH which gets replaced during preprocessing by the string literal "/path/to/file". Alternatively, a const global variable which type is char can be used. e.g. char const* MY_PATH = "/path/to/file";

Upvotes: 1

Related Questions