1、数组
int main()
{
char a[] = "Metax";
char* b = "Metax";
char* c[] = { "Metax", "Tech" };
char d[5] = { 'M', 'e', 't', 'a', 'x' };
printf("%d, %d, %d, %d\n", sizeof(a), sizeof(b), sizeof(c), sizeof(d));
return 0;
}
2、三维数组
int main()
{
int a[2][3][4] = { { { 1, 2, 3 }, { 4, 5, 6 } }, { { 7, 8, 9 }, { 10, 11, 12 } } };
int* ptr = (int*)(&a + 1);
std::cout << *(int*)(a + 1) << endl;
std::cout << *(ptr - 1) << endl;
return 0;
}
3、二维字符数组初始化
int main()
{
// 其余三种都无效
//char str[2][3] = { { 'a', 'b' }, { 'c', 'd' }, { 'e', 'f' } };
char str[2][3] = { "a", "b" };
//char str1[2] = { "a", "b" };
//char*str = { "a", "b" };
return 0;
}
4、运算符实操
int main()
{
int a = 5, b = 6, c = 7, d = 8;
int m = 2, n = 2;
cout << ((m = a > b) && (n = c > d)) << endl; // 因为&&前面不成立,所以不会走后面的
cout << n << endl;
return 0;
}
5、unsigned char* 和 unsigned long*
int main()
{
unsigned char* p1 = (unsigned char*)0x801000;
unsigned long* p2 = (unsigned long*)0x810000;
p1 = p1 + 5;
p2 = p2 + 5;
return 0;
}
vs2013在32位
vs2013在64位
6、构造测试
class A
{
public:
A(int a = 0)
: _a(a)
{
cout << "构造" << endl;
}
private:
int _a;
};
int main()
{
A a(2);
A b[3];
A*p[4]; // p:未引用的局部变量
return 0;
}
7、复杂函数看法
void* (*func[4])(int(*)(int*, int*), char const*);
这是一个函数指针数组,返回值为void*
第一个参数是函数指针,返回值为int,两个参数都是int*
第二个参数是 char const*
8、枚举测试
enum T1
{
red,
black,
blue = 6,
bubu,
yellow = 10
};
int main()
{
cout << red << " " << black << " " << blue << " " << bubu << " " << yellow << endl;
return 0;
}