首页 > C/C++语言 > C/C++基本语法 > C 的入门者请进,否则不要花时间click
2005
12-12

C 的入门者请进,否则不要花时间click

只需要把下面代码paste到new project, run, 即看到效果



// Feb 4th, 2002



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




double foo(int a,double *b);



int main(void)
{



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; //Square; if a=3, return 9;
printf(“(*b) *= *b;\n”);

//b=b+1; //[NO] make b to another address;
//*b=*b+1; //[YES] value itself +1;
/*
double k = 2;
printf(“1.1…pAddress(&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); // works also



}


留下一个回复