- 宏定义,#,##
##——连接两个参数
#include <iostream>
using namespace std;
#define TEST(pid) (cout<<para##pid<<endl);
#define TEST2(p) (cout<<#p<<endl);
int main()
{
int para3 = 3;
int para2 = 2;
TEST(2); //<==>cout<<para2<<endl;
TEST(3); //<==>cout<<para3<<endl;
TEST2(test) //<==>cout<<"test"<<endl;
TEST2("test2"); //<==>cout<<""test2""<<endl;
system("pause");
return 0;
}
using namespace std;
#define TEST(pid) (cout<<para##pid<<endl);
#define TEST2(p) (cout<<#p<<endl);
int main()
{
int para3 = 3;
int para2 = 2;
TEST(2); //<==>cout<<para2<<endl;
TEST(3); //<==>cout<<para3<<endl;
TEST2(test) //<==>cout<<"test"<<endl;
TEST2("test2"); //<==>cout<<""test2""<<endl;
system("pause");
return 0;
}
- const修饰指针
int a = 10;
int b = 20;
const int* p1 = &a; //ok
p1 = &b; //ok
//*i = 11; //error
int* const p2 = &a; //ok
*p2 = a; //ok
//p2 = &b; //error
const int* p3; //ok
//int* const p4; //error, must be initialized
int b = 20;
const int* p1 = &a; //ok
p1 = &b; //ok
//*i = 11; //error
int* const p2 = &a; //ok
*p2 = a; //ok
//p2 = &b; //error
const int* p3; //ok
//int* const p4; //error, must be initialized
- 声明函数指针数组
#include <stdlib.h>
#include <stdio.h>
//typedef void (*pf) ();
void f1(){};
void f2(){};
int main()
{
void (*pf[2]) ()={f1,f2};
system("pause");
return 0;
}
#include <stdio.h>
//typedef void (*pf) ();
void f1(){};
void f2(){};
int main()
{
void (*pf[2]) ()={f1,f2};
system("pause");
return 0;
}
#include <stdlib.h>
#include <stdio.h>
typedef void (*pf) ();
void f1(){};
void f2(){};
int main()
{
//void (*pf[2]) ()={f1,f2};
pf p[2]={f1,f2};
system("pause");
return 0;
}
#include <stdio.h>
typedef void (*pf) ();
void f1(){};
void f2(){};
int main()
{
//void (*pf[2]) ()={f1,f2};
pf p[2]={f1,f2};
system("pause");
return 0;
}