1,typedef简化输入
在编程中如果用到结构体,每次定义变量时都要输很长的代码,特别是在建链表时,经常重复输入struct…,为了避免这种重复,可以用typedef 。
不过不建议在实际的编程中运用,但在竞赛中为了更快的输入,这确实是一个好方法。
如:
#include<iostream>
using namespace std;
struct TEMP
{
int a;
int b;
};
int main()
{
struct TEMP one;
struct TEMP *tow;
typedef struct TEMP temp;
typedef struct TEMP * ptemp;
temp one_1;//相当于struct TEMP one_1;
ptemp tow_1;//相当于struct TEMP *tow_1;
return 0;
}
2,简化for循环输入
和typedef的思想一样,for循环输入的简化也是用一个简单的东西代替比较长的for循环,不过其实这个不怎么实用,只有当程序中经常遇到同一种类型的for循环才实用。
#include<iostream>
using namespace std;
#define F(i,a,b) fro(int i=(a);i>=(b);i++)
int main()
{
int i;
F(i,0,5)
cout<<i;
//相当于
for(i=0;i>=5;i++)
cout<<i;
return 0;
}