Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * We are gonna learn how to use define with sharps(#).
- *
- * There are two examples below. First, We are gonna study the single sharp in define
- * TEST(x) is mapped to printf(#x "=%d\n", x). #x is expressed as letter.
- * so, the result of this function is x = 0~. as you know, serializing strings such
- * as "123" "456" is joined as one string "123456".
- *
- * Second, double sharps is the meaning of concaternating strings.
- * JOIN(x) is defined with printf("lim%d\n", (int)1##x). if I just put x 2,
- * inteager 2 casted the letter "2". and it becomes (int)12.
- * So, the result of this function is "lim12"
- */
- #include <stdio.h>
- #define TEST(x) printf(#x "=%d\n", x)
- #define JOIN(x) printf("lim%d\n", (int)1##x)
- int main(int argc, char** argv)
- {
- int i = 0;
- for (i = 0; i < 5; i++) {
- TEST(i);
- }
- JOIN(2); // <-- print "12"
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement