+ 2
Can anyone explain me the token pasting operator in preprocessor..?
7 Antworten
+ 5
The ##x preprocessor operator is used to glue things together in the preprocessor code.
It is a concatenation operator which can join two literals, tokens, anything into a single one..
Eg
#define cat(x,y) cout<<x##y;
main()
{
cat("a","b"); //ab
cat(2,3); //23
cat('a',2); //a2
}
You may also enter types here, but they may not work in this one...
But they may work in cases where you wish to create the variables at runtime or overload them for all types...
Eg - https://code.sololearn.com/cT79Zt0zSHSo/?ref=app
This uses ##x to get a data type and create a structure for that datatype, thus, allowing the user to use the same structure for more than one data type...
Read more here:
https://gcc.gnu.org/onlinedocs/cpp/Concatenation.html
+ 3
yep
+ 3
Okk..Thank you @kinshuk 😊👍
+ 2
You mean ##x?
+ 1
@Prahar pandya
Welcome...