|
#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 */
} |
|