Following preprocessor operators are available in C++ that could be used with the #define directive.
- # is stringify operator turns the operand into a string. Can be used only in macro replacement text. Macro parameter name must follow this operator.
- ## is concatentation operator to cat preprocessor tokens. Can be used only in macro replacement text. Must not appear in the beginning or end of replacement text.
#include <iostream>
using namespace std;
#define myprint1(a) cout << #a << endl
#define myprint2(a,b) cout << a##b << endl
int main()
{
myprint1(hello);
myprint2("hello","world");
return 0;
}
OUTPUT:-
hello
helloworld
The statement below is giving the error:
ReplyDelete"hello and world does not give a valid preprocessing token"
#define myprint2(a,b) cout << a##b << endl