LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1069|回复: 0

提供一些代码供菜鸟分析和借鉴!!!

[复制链接]
发表于 2002-11-7 20:49:29 | 显示全部楼层 |阅读模式
#include <stdio.h>
#include <string.h>
#include <stdlib.h>


double foo(int a,double *b);

int main()
{ double y=0,z=0;
  printf("\n0.....y Address = %p\n",&y);  /*print y address*/
  z=foo(3,&y);     /*Square; if 3,return z=9; if 4,z=16 ....*/
  printf("\nz = 3*y = %2.0f\n",z);

  return 0;
}


double foo(int a,double *b)
{ printf("1.......pAddress(b) = %p,double value(*b) = %f\n",b,*b);
  *b=a;
  (*b) *=*b;   /*Suqare; if a=3,return 9; */
  printf("(*b) *=*b;\n");

  /* b=b+1; [No] make b to anther address;*/
  *b=*b+1;  [yes] value itself +1 */
  /*
  double k=2;
  printf("1.1.....p Address(&k) = %p\n",&k);
  b=&k;   /*[yes] if b= sth's address ,*b=sth's value */
  printf("b = &k;\n");
  printf("2....pAddress(b) = &p,double value(*b) =%f\n\n",b,*b);
  */

  return *b;

  /* return b;  [No] cannot convert from 'double *' to 'double'  */
  /* return (*b)*(*b);  work also */

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

本版积分规则

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