C 指针改变变量值

/**

*通过指针改变局部变量值

**/

#include"stdio.h"
#include"stdlib.h"
void work(char* chuck)
{
int i;
*chuck = 'c';
printf("first:%c\n",*chuck);
}
void main()
{
char chuck='a';
char *p = &chuck;
work(p);
printf("%c\n",*p);
}

/**

*修改第三个字符为大写

**/

#include <stdio.h>
#include <stdlib.h>

void work(char* chuck)
{
int i;

for(i=0; i<7; i++)
{
if(i==2)
{
printf("%c\n",*(chuck+i)='C');
break;
}

}
printf("%s\n",chuck);
}

void main()
{

char chuck[]="abcd";
work(chuck);
printf("%s\n",chuck);
getchar();
return;

}

/**

*修改第四个字符为大写

**/

#include <stdio.h>
#include <stdlib.h>

void main()
{
char str[] = "abcdef";
char *p_str = str;
printf("%s\n", p_str);
char str_2[] = "fedcba";
p_str = str_2;
printf("%s\n", p_str);
*(p_str+3) = 'D'; //修改第四个字符为大写
printf("%s\n", p_str);

}

上一篇:出现The folder is already a source folder


下一篇:再见了我热爱的ACM赛场