C语言 通过指针和二级指针遥控数据

// PointerArray.cpp : 定义控制台应用程序的入口点。
//vs2015

#include “stdafx.h”
#include <stdlib.h>
void test1(int* p)
{
*p = 1;
}
void test2(int *p,int n)
{
int i = 0;
while (i<n)
{
*p = 10 * i + 15;
p++;
i++;
}
}
int main()
{
int n = 10;
test1(&n);
printf(“n=10通过指针改变为n=%d\n”, n);//1
int ar[10] = { 1,2,3,4,5,6,7,8,9,10 };
int *p = ar;
test2(p,_countof(ar));
int i=0;
while (i<10)
{
printf(“ar[%d]的数据通过指针变为%d\n”,i, ar[i]);
i++;
}
return 0;
}


// PointerArray.cpp : 定义控制台应用程序的入口点。
//vs2015

#include “stdafx.h”
#include <stdlib.h>
void test1(char* p)
{
*p = ‘b’;
}
void test2(char *p,int n)
{
int i = 0;
while (i<n)
{
*p = *p - 32;
p++;
i++;
}
}

int main()
{
char c = ‘a’;
test1(&c);
printf(“c=a通过指针改变为c=%c\n”,c);//b
char ar[10] = {‘a’,‘b’,‘c’,‘d’,‘e’,‘f’,‘g’,‘h’,‘i’,‘j’};
char *p = ar;
test2(p,_countof(ar));
int i=0;
while (i<10)
{
printf(“ar[%d]的数据通过指针变为%c\n”,i, ar[i]);//A B C D E F G H I J
i++;
}
return 0;
}


// PointerArray.cpp : 定义控制台应用程序的入口点。
//vs2015

#include “stdafx.h”
#include <stdlib.h>

char s[] = “bbb”;
void test1(char** pp)
{
*pp = “bbb”;
}
void test2(char **pp,int n)
{
char *arr[10] = { “aaa”,“bbb”,“ccc”,“ddd”,“eee”,“fff”,“ggg”,“hhh”,“iii”,“kkk” };
int i = 0;
while (i<n)
{
pp = arr[i];
pp++;
i++;
}
}
int main()
{
char
c = “abbb”;
char **pp = &c;
test1(pp);
printf(“c=abbb通过指针改变为c=%s\n”,c);//bbb
char *ar[10] = {“afdf”,“bdfs”,“csfs”,“dwe”,“dfse”,“fggf”,“cvvg”,“wrh”,“gfdi”,“fdfdj”};
char **pp1 = ar;
//test2(pp1,_countof(ar));
test2(ar, _countof(ar));
int i=0;
while (i<10)
{
printf(“ar[%d]的数据通过指针变为%s\n”,i, ar[i]);//运行结果"aaa",“bbb”,“ccc”,“ddd”,"
i++; ///eee",“fff”,“ggg”,“hhh”,“iii”,“kkk”

}
return 0;

}
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_43769045/article/details/84876045