by Dinesh Thakur Category: Preprocessor Directives

The token # single in its own line is null directive. It is simply neglected by compiler. Thus, if the code is simply as given below, it is neglected by the compiler.


However, if it is used in a #define statement of a macro, then# is taken as replacement token. For example:

#define Func(Z) printf("Hello #Z How are you?)

The operator sin the expression #z is replacement token, i.e., it replaces the value wherever z appears. The replacement is converted into a string with double quotes. For example, consider the following application of the above code:

#define F(z) printf ("Good Morning " #z)

When function F (z) is called as F (Shubhra), it is equivalent to the following statement:

printf ("Good Morning Shubhra");


The preprocessor operator ## is used along with #define and it puts together (concatenates) two tokens. For example, consider the following code for an illustration:

#define concat(A,B) A ## B

The above code would give output as AB. Thus, if the macro is called in the program as concat (1, 00) the output would be 100. Program provides an illustration.


#define Func1(Z) printf("Hello" #Z" How are you?")
#define Concate(a, b) a ## b
void main()
  Func1 (Shubhra!);
  printf("Concatenate 1 and 00 = %d\n", Concate(1, 00) );
  printf("Concatenate names= %s\n", Concate( "Shubhra", "Thakur"));
  printf("%s\n", Concate( "Let us learn" , "only C language."));

Preprocessor operator ##.

About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.C.A, MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.