鱼C论坛

 找回密码
 立即注册
查看: 3931|回复: 7

二级指针错误?

[复制链接]
发表于 2018-5-25 18:38:41 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
#define _CRT_SECURE_NO_WARINGS
#include <stdio.h>
#include<stdlib.h>
#include<string.h>


void GetMem(char **p)
{
        *p=400;
}


void GetMem1(char *p)
{
        *p=800;
}


void main()

{
        char *p1=NULL;
        char **p2=NULL;

        GetMem(&p1);
        printf("p1: %p\n",p1);
        GetMem1(&p1);
        printf("p1:%p\n",p1);




system("pause");
return;
}

QQ图片20180525183754.png
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2018-5-25 19:00:41 | 显示全部楼层
何意?你具体想说什么问题????
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2018-5-25 19:19:14 | 显示全部楼层
ba21 发表于 2018-5-25 19:00
何意?你具体想说什么问题????

第二次打赢P1应该是320,怎么会是120?
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-5-25 21:17:41 | 显示全部楼层
本帖最后由 ba21 于 2018-5-25 21:22 编辑
Mr.HO 发表于 2018-5-25 19:19
第二次打赢P1应该是320,怎么会是120?


自己看图理解。还有要指出的是请正规化,别整些没用的;搞得自己头晕

2018-05-25_211548.png

  1. #include <stdio.h>
  2. #include<stdlib.h>
  3. #include<string.h>


  4. void a(int **p)
  5. {
  6.         int newa;
  7.         newa = 520;

  8.         *p=&newa;
  9. }


  10. void b(int *p)
  11. {
  12.         *p=800;
  13. }


  14. void main()

  15. {
  16.         int *p1=NULL;


  17.         a(&p1);
  18.                 printf("p1 = %d\n", *p1);

  19.         b(p1);

  20.         printf("p1 = %d\n", *p1);


  21. system("pause");
  22. return;
  23. }
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2018-5-25 23:46:42 | 显示全部楼层
ba21 发表于 2018-5-25 21:17
自己看图理解。还有要指出的是请正规化,别整些没用的;搞得自己头晕

类型错误了
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2018-5-26 00:09:41 | 显示全部楼层
#define _CRT_SECURE_NO_WARINGS
#include <stdio.h>
#include<stdlib.h>
#include<string.h>


void printp(char **p)
{


        printf("%p\n",p);
        printf("%p\n",*p);
        printf("%p\n",**p);
}

void printp1(char *p)
{


        printf("%p\n",p);
        printf("%p\n",*p);
}


void main()

{



        //char *p[]={"hojanan","hojing"};
        char *p="test";
        /*char **p1;
        char p2;
        char **********p3;
        char ****p4;
        */
        printp(&p);
        printf("\n");
        printp1(&p);
        //printf("%d %d %d  %d  %d",sizeof(p),sizeof(p1),sizeof(p2),sizeof(p3),sizeof(p4));


system("pause");
return;
}
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2018-5-26 00:10:11 | 显示全部楼层
#define _CRT_SECURE_NO_WARINGS
#include <stdio.h>
#include<stdlib.h>
#include<string.h>


void printp(char **p)
{


        printf("%p\n",p);
        printf("%p\n",*p);
        printf("%p\n",**p);
}

void printp1(char *p)
{


        printf("%p\n",p);
        printf("%p\n",*p);
}


void main()

{



        //char *p[]={"hojanan","hojing"};
        char *p="test";
        /*char **p1;
        char p2;
        char **********p3;
        char ****p4;
        */
        printp(&p);
        printf("\n");
        printp1(&p);
        //printf("%d %d %d  %d  %d",sizeof(p),sizeof(p1),sizeof(p2),sizeof(p3),sizeof(p4));


system("pause");
return;
}
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2018-5-26 00:10:52 | 显示全部楼层
  1. #define _CRT_SECURE_NO_WARINGS
  2. #include <stdio.h>
  3. #include<stdlib.h>
  4. #include<string.h>


  5. void printp(char **p)
  6. {


  7.         printf("%p\n",p);
  8.         printf("%p\n",*p);
  9.         printf("%p\n",**p);
  10. }

  11. void printp1(char *p)
  12. {


  13.         printf("%p\n",p);
  14.         printf("%p\n",*p);
  15. }


  16. void main()

  17. {



  18.         //char *p[]={"hojanan","hojing"};
  19.         char *p="test";
  20.         /*char **p1;
  21.         char p2;
  22.         char **********p3;
  23.         char ****p4;
  24.         */
  25.         printp(&p);
  26.         printf("\n");
  27.         printp1(&p);
  28.         //printf("%d %d %d  %d  %d",sizeof(p),sizeof(p1),sizeof(p2),sizeof(p3),sizeof(p4));


  29. system("pause");
  30. return;
  31. }
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-6-9 17:02

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表