在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
#include<stdio.h> #define Operations(x) operation_ ## x // ## 是黏贴字符串 int Operations(sum)(int x,int y){ // operation_sum(int x,int y) return x+y; } int Operations(sub)(int x,int y){ // operation_sub(int x,int y) return x-y; } int Operations(mul)(int x,int y){ // operation_mul(int x,int y) return x*y; } float Operations(div)(float x,float y){ // operation_div(int x,int y) float result; result =x/y; return result; } #define Print(x) printf("%s,%d\n",#x,x); // # 表示将参数转变为字符串 int main() { int x; float y; x=Operations(sum)(10,20); printf("x=%d\n",x); x=operation_sum(100,20); printf("x=%d\n",x); x=Operations(sub)(10,20); // operation_sub(10,20)也可以 printf("x=%d\n",x); x=Operations(mul)(10,20); // operation_mul(10,20)也可以 printf("x=%d\n",x); y=Operations(div)(11,20); // operation_div(11,20)也可以 printf("y=%lf\n",y); Print(100); return 0; } 注:##连接两边字符串。 |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论