ACM_编程与调试重点记录(十三)

来源:互联网 发布:千牛mac下载 编辑:程序博客网 时间:2024/06/07 03:49

1.如何通过指针返回多个值?

#include"stdio.h"

void swap(int *p1,int *p2)

{

       int p;

       p=*p1;*p1=*p2;*p2=p;

}

 

int main()

{

       int a=3,b=4;

       int *ptr1,*ptr2;

       ptr1=&a;ptr2=&b;

       if(a<b) swap(ptr1,ptr2);

       printf("%d  %d/n",a,b);

}

运行结果:

 

4  3

请按任意键继续. . .

 

2.请看:

坐标法

 

 

 

 

 

 

 

 

 

指针法

#include"stdio.h"

int main()

{

    struct w

    {

        int a;

        int b[100];

        double c[10];

    }e;

    printf("%d/n%d/n%d/n/n",sizeof(e.a),sizeof(e.b[0]),sizeof(e.c[0]));

    printf("%d/n%d/n%d/n%d/n",sizeof(e.a),sizeof(e.b),sizeof(e.c),sizeof(w));

}

运行结果:

 

4

4

8

 

4

400

80

488[GP1] 

请按任意键继续. . .

3.*&的作用与联系


 [GP1]为什么是488,而不是484呢???