#include <iostream>
#include <stdlib.h>
using namespace std;
///////////////////////////////////////////////////////////
void TestPointArray();
//////////////////////////////////////////////////////////
void TestConstRef()
{
int a = 100;
const int &b = a;
cout<<b<<endl; // 100
a = 2;
cout<<b<<endl; // 2
// b = 1; // error
const int &c = 300;
cout<<c<<endl;
}
void TestSizeof()
{
char s1[6] = "ABCDE";
char *s2 = "abcde";
char s3[] = "abcde";
cout<<sizeof(s1)<<endl; // 6
cout<<sizeof(s2)<<endl; // 4
cout<<sizeof(s3)<<endl; // 6
}
void TestArray()
{
int a[] = {1, 2, 3, 4, 5};
int *p = a;
cout<<p<<endl; // 0x22ff50
cout<<*p++<<endl;
cout<<p<<endl; // ?
cout<<p - a<<endl; // ?
cout<<*++p<<endl; // 3
cout<<*(p + 1)<<endl;
cout<<*((int*)((char *)p + 1))<<endl; // 哈哈, 是 0x4000
}
void TestArrPara(int a[5])
{
cout<< *(a++)<<endl; // OK
}
int main(int argc, char *argv[])
{
// TestConstRef();
// TestSizeof();
// TestArray();
int a[] = {1, 2, 3, 4, 5};
// TestArrPara(a);
TestPointArray();
system("PAUSE");
return 0;
}
void TestPointArray()
{
int a[] = {1, 2, 3, 4, 5};
int (*p)[5];
p = &a;
cout<<*p[0]<<endl;
cout<<*p[1]<<endl;
cout<<*p[2]<<endl;
cout<<*p[3]<<endl;
cout<<*p[4]<<endl;
cout<<endl;
cout<<(*p)[0]<<endl;
cout<<(*p)[1]<<endl;
cout<<(*p)[2]<<endl;
cout<<(*p)[3]<<endl;
cout<<(*p)[4]<<endl;
cout<<endl;
cout<<p[0]<<endl;
cout<<p[1]<<endl;
cout<<p[2]<<endl;
cout<<p[3]<<endl;
cout<<p[4]<<endl;
cout<<endl;
cout<<a + 0<<endl;
cout<<a + 1<<endl;
cout<<a + 2<<endl;
cout<<a + 3<<endl;
cout<<a + 4<<endl;
cout<<endl;
int *q = *p;
cout<< *++q<<endl;
}
#include <stdlib.h>
using namespace std;
///////////////////////////////////////////////////////////
void TestPointArray();
//////////////////////////////////////////////////////////
void TestConstRef()
{
int a = 100;
const int &b = a;
cout<<b<<endl; // 100
a = 2;
cout<<b<<endl; // 2
// b = 1; // error
const int &c = 300;
cout<<c<<endl;
}
void TestSizeof()
{
char s1[6] = "ABCDE";
char *s2 = "abcde";
char s3[] = "abcde";
cout<<sizeof(s1)<<endl; // 6
cout<<sizeof(s2)<<endl; // 4
cout<<sizeof(s3)<<endl; // 6
}
void TestArray()
{
int a[] = {1, 2, 3, 4, 5};
int *p = a;
cout<<p<<endl; // 0x22ff50
cout<<*p++<<endl;
cout<<p<<endl; // ?
cout<<p - a<<endl; // ?
cout<<*++p<<endl; // 3
cout<<*(p + 1)<<endl;
cout<<*((int*)((char *)p + 1))<<endl; // 哈哈, 是 0x4000
}
void TestArrPara(int a[5])
{
cout<< *(a++)<<endl; // OK
}
int main(int argc, char *argv[])
{
// TestConstRef();
// TestSizeof();
// TestArray();
int a[] = {1, 2, 3, 4, 5};
// TestArrPara(a);
TestPointArray();
system("PAUSE");
return 0;
}
void TestPointArray()
{
int a[] = {1, 2, 3, 4, 5};
int (*p)[5];
p = &a;
cout<<*p[0]<<endl;
cout<<*p[1]<<endl;
cout<<*p[2]<<endl;
cout<<*p[3]<<endl;
cout<<*p[4]<<endl;
cout<<endl;
cout<<(*p)[0]<<endl;
cout<<(*p)[1]<<endl;
cout<<(*p)[2]<<endl;
cout<<(*p)[3]<<endl;
cout<<(*p)[4]<<endl;
cout<<endl;
cout<<p[0]<<endl;
cout<<p[1]<<endl;
cout<<p[2]<<endl;
cout<<p[3]<<endl;
cout<<p[4]<<endl;
cout<<endl;
cout<<a + 0<<endl;
cout<<a + 1<<endl;
cout<<a + 2<<endl;
cout<<a + 3<<endl;
cout<<a + 4<<endl;
cout<<endl;
int *q = *p;
cout<< *++q<<endl;
}