VC语言

本类阅读TOP10

·VC++ 学习笔记(二)
·用Visual C++打造IE浏览器(1)
·每个开发人员现在应该下载的十种必备工具
·教你用VC6做QQ对对碰外挂程序
·Netmsg 局域网聊天程序
·Windows消息大全
·VC++下使用ADO编写数据库程序
·VC++学习笔记(四)
·非法探取密码的原理及其防范
·怎样在VC++中访问、修改注册表

分类导航
VC语言Delphi
VB语言ASP
PerlJava
Script数据库
其他语言游戏开发
文件格式网站制作
软件工程.NET开发
C 的入门者请进,否则不要花时间click

作者:未知 来源:月光软件站 加入时间:2005-2-28 月光软件站

//只需要把下面代码paste到new project, run, 即看到效果
//The goal of this program is to show:
// the relationship of Pointer and Address in C languange.

//created by Feb 4th, 2002   
//modified by Feb 4th,2004

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

 //if put   3, result=3^3+3=12;
 //if       4, result=4^4+4=20...
double squarePlus(int a,double *b);

int main(void)
{
    double x=3,y=3,result=0;
    printf("\n 0.....y Address = %p\n",&y); // print y address

 //scanf(y);
    result=squarePlus(3,&y);    
                                
    printf("\n SquarePlus of %f = %2.0f \n",x,result);

 return 0;
}
/*

 0.....y Address = 0012FF70
 1.....pAddress(b) = 0012FF70
 2.....double value(*b) = 3.000000
...processing: (*b) *= *b;

 SquarePlus of 3.000000 = 12
Press any key to continue

*/

//**********************************************************//
double squarePlus(int a,double *b)
{
   //Print the address of pointer:
   printf(" 1.....pAddress(b) = %p \n",b);

   //Print the value after calcuation:
   printf(" 2.....double value(*b) = %f\n",*b);

   //Save before you have to change.
   double k = *b;  
   //b=&k; //[YES] if b= sth's address;
            //        *b= sth's value;


   // b is always the Result:
   *b=a;
   (*b) *= *b;                 //multipile itself
   printf("...processing: (*b) *= *b;\n");
 
   *b=*b+k;        //[YES] value itself +1;
   //b=b+b;        //[NO]  just make "b" to another address;

   return *b;
   //return (*b)*(*b)+(*b);  //[YES] works also
   //return b;      // [NO] cannot convert from 'double *' to 'double'
}

//http://www.eurasia.edu/bbs/ti_view.asp?FN_id=15&FC_root_id=115073&FC_id=115073





相关文章

相关软件