#运算符用于在预编译时, convert the macro argument to a string
eg.
#include <stdio.h>
#define CONVERT (f) (#f)
void HelloWorld ()
{
printf ("Hi,tom Welcome to You! ");
}
int main ()
{
printf ("%s\n", CONVERT (Hello world!));
printf ("%s\n", CONVERT (100));
printf ("%s\n", CONVERT (while));
printf ("%s\n", CONVERT (return));
printf ("%s\n", CONVERT (HelloWorld));
return 0;
}
Output:
printf ("%s\n", CONVERT (HelloWorld)); This sentence does not execute the contents of the function, there is no output: printf ("Hi,tom Welcome to You! ");
The convert macro simply outputs the name of the function.
# #运算符则用于在预编译时, adhesion two symbols
In general, we define the structure as follows:
#include <stdio.h>
typedef struct _STUDENT
{
int id;
char* name;
}student;
int main ()
{
Student S1;
s1.id=1;
S1.name= "TTH";
printf ("id:%d\n", s1.id);
printf ("name:%s\n", s1.name);
Student *p1;
p1=&s1;
printf ("p1-id:%d\n", p1->id);
printf ("p1-name:%s\n", p1->name);
return 0;
}
When we have the # #运算符符后, we can define the structure as follows:
#include <stdio.h>
#define STUDENT (type) typedef struct _# #type type;\
struct _# #type
STUDENT (STUDENT)
{
int id;
Char *name;
};
int main ()
{
Student S1;
s1.id=1;
S1.name= "TTH";
printf ("id:%d", s1.id);
printf ("name:%s", s1.name);
return 0;
}
Output:
C in about # and # #的简易使用