数组指针--指针指向一个数组

╄→尐↘猪︶ㄣ 提交于 2020-01-20 03:27:08
#include <stdio.h>
#include <iostream>
using namespace std;
int main(void)
{
	int a[10] = { 1,2,3,4,5,6,7,8,9,10 };
	int(*p)[10]; //先算小括号,p和*结合,属于指针类型,指针指向拥有十个int型元素的数组
				 //p=a;等价于int (*p)[10]=&a;
	p = &a;
	printf("%d\t%d\n", sizeof(p), sizeof(*p));
	printf("%d\n", (*p)[3]);
	system("pause");
}

#include <stdio.h>
#include <iostream>
using namespace std;
int main(void)
{
	char str[3][20] = { "hello","world","itcast" };
	char(*p)[20];//行指针,str[3][20]共三行,每行20个字节

	p = &str[0];
	printf("%s\n", *(p + 1));//+1==向后走了20个字节,因为每个单词五个字母
	
	system("pause");
	return 0;
}

 

#include <stdio.h>
#include <iostream>
using namespace std;
int main(void)
{
	char str[3][20] = { "hello","world","itcast" };
	//char(*p)[20];//行指针,str[3][20]共三行,每行20个字节
	char *p;
	p = str[0];
	printf("%s\n", (p + 1));//+1==向后走了20个字节,因为每个单词五个字母
	printf("%s\n", (p + 20));//+1==向后走了20个字节,因为每个单词五个字母

	system("pause");
	return 0;
}

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!