(1)基础练习:typedef。
#include <iostream> using namespace std; typedef int I; typedef double D; int main(){ int a=1; I b=2; double c=1.00; D d=2.00; cout<<a<<c<<endl; cout<<b<<d<<endl; } 输出结果为
11
22
I和D可以分别实现int和double的功能。
(2)定义指针名称。
#include <iostream> using namespace std; typedef int(*xiaot)(int,int); int add(int a,int b) { return a+b; } int main() { int(*p)(int,int)=add; int a=p(1,2); xiaot X=add; int b=X(3,4); cout<<a<<endl; cout<<b; }
输出结果
3
7
使用xiaot这个名字也可定义指针,定义名称的方法稍有不同。
转载请注明原文地址: https://ju.6miu.com/read-36871.html