coperatorsoperator-keyword

What is '#' operator in C?


Is there a '#' operator in C ?

If yes then in the code

enum {ALPS, ANDES, HIMALYAS};

what would the following return ?

 #ALPS 

Solution

  • The C language does not have an # operator, but the pre-processor (the program that handles #include and #define) does. The pre-processor simple makes #ALPS into the string "ALPS".

    However, this "stringify" operator can only be used in the #define pre-processor directive. For example:

    #define MAKE_STRING_OF_IDENTIFIER(x)  #x
    char alps[] = MAKE_STRING_OF_IDENTIFIER(ALPS);
    

    The pre-processor will convert the above example into the following:

    char alps[] = "ALPS";