本文介绍了C预处理器 - 示例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞!#include<stdio.h>#define SWAP(a, b, c)(c t; t=a, a=b, b=t)int main(){ int x=10, y=20; SWAP(x, y, int); printf("%d %d\n", x, y); return 0;} 为什么不允许int声明?我们可以在一个paranthesis中声明吗?是否允许?why it is not allowing int to be declared?can we declare inside a paranthesis?whether it is allowed?推荐答案#define SWAP(a,b,c) do {c t=a; a=b; b=t;}while(0) 执行构造确保您可以执行以下操作:The do while construct ensures that you can do something like this:if(x < y) SWAP(x,y,int);else y++;// rest of your code 没有不良副作用 - 我建议你使用std :: swap。 最好的问候 Espen HarlinnWithout undesired side effects - I would advice you to use std::swap.Best regardsEspen Harlinn 这篇关于C预处理器 - 示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
07-26 08:42