//多为数组的指针学习
//定义二位数组
//int date[4][5];
//说明这个数组的所有成员都是int类型
//int date[4][5] = {
// {1, 2, 3, 4, 5},
// {1, 2, 3, 4, 5},
// {1, 2, 3, 4, 5},
// {1, 2, 3, 4, 5}
//};
//或者int date[4][5] = {1,2,3,4,5,1,2,3,4,5,1,2,3,4,5,1,2,3,4,5};
//例子访问二位数组
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
int date[4][5] = {
{1, 2, 3, 4, 5},
{1, 2, 3, 4, 5},
{1, 2, 3, 4, 5},
{1, 2, 3, 4, 5},
};
printf("date[4][5]:\n");
for(int i = 0; i < 4; ++i)
{
for(int j = 0; j < 5; ++j)
{
printf("%d ", date[i][j]);
}
printf("\n");
}
return 0;
}
//指针与二维数组
//利用指针查看每个元素在内存的地址是多少?
//急事把指针指向每个内存单元的开始
//例如 &date[i][j] 就是去每个元素的地址的意思。
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
int date[4][5] = {{1, 2, 3, 4, 5}};
printf("每个元素的地址是:");
for(int i = 0; i < 4; ++i)
{
for(int j = 0; j < 5; ++j)
{
printf("%p\t", &date[i][j]);
}
printf("\n");
}
return 0;
}
//指针的指针
//
//int * *date;
//指向指针变量的指针;
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
char *name[] = {"China", "BeiJing", "LongMai"};
char ** p_name;
printf("name[0] :%p\n", name[0]);
printf("name[1] :%p\n", name[1]);
printf("name[2] :%p\n", name[2]);
printf("\n");
p_name = &name[0];
printf("&name[0] : %p\n", p_name);
p_name = &name[1];
printf("&name[1] : %p\n", p_name);
p_name = &name[2];
printf("&name[2] : %p\n", p_name);
printf("\n");
return 0;
}