首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

二级一路题!关于指针、函数、数组

2012-09-27 
二级一道题!关于指针、函数、数组C/C++ code#include stdio.h#include string.hvoid point(char *p){p++

二级一道题!关于指针、函数、数组

C/C++ code
#include <stdio.h>#include <string.h>void point(char *p){    p++;}main(){    char *p;    char b[4]={'a','b','c','d'};    p=b;    point(p);    printf("%c\n",*p);}


结果是a,不是p++了吗,那不是b吗 为什么会是a?

[解决办法]
C/C++ code
//================================================================= #include <windows.h>    #include <iostream.h> #include <stdio.h>#include <string.h>void point(char **p){    (*p)++;}main(){    char *p;    char b[4]={'a','b','c','d'};    p=b;    point(&p);    printf("%c\n",*p);}
[解决办法]
探讨
你的:
void point(char *p)
{
p++;
}
这里的p虽然移动了,但是p=b;的这个p实际没有发生变化

[解决办法]
C/C++ code
#include <stdio.h>#include <string.h>void point(char *p){    p++;}void point_p(char* p){    (*p)++;}void main(){    char *p;    char b[4]={'a','b','c','d'};    p=b;    //p++;    printf("%c\n",*p);    //point(p);    point_p(p);        printf("%c\n",*p);}
[解决办法]
探讨

C/C++ code

#include <stdio.h>
#include <string.h>

void point(char *p)
{
p++;
}
void point_p(char* p)
{
(*p)++;
}
void main()
{
char *p;
char b[4]={'a','b','c','d'};
p=b;
//……

热点排行