1

Is it possible to define a string as char in C like this? I think C calls it multi character constant.

#define OK '_/'

I want C to treat '_/' as a char from now on, not a string, so this:

printf("%c", OK);

prints _/ and not /

ijkl
  • 23
  • 3

2 Answers2

2

Multi character constants are of int type and their value is not strictly defined-- it's platform dependent stuff. So using them as normal letters is not best idea, even though you can use them in every context as normal char there is no guarantee that they will be compiled as you intend (as in your example you get only last char from ur string). here you have explanation of the topic: Multiple characters in a character constant

Community
  • 1
  • 1
Dominik
  • 331
  • 1
  • 4
  • 12
2

While it is technically valid C to define OK as '_/', the value of a multi-character character constant is implementation defined, so this is probably not something you want to do.

There is no way you will be able to print more than one character without resorting to strings.

Filipe Gonçalves
  • 20,783
  • 6
  • 53
  • 70