C 的入门者请进,否则不要花时间click
2004-02-05 18:21
525 查看
//只需要把下面代码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
//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
相关文章推荐
- 一个从Microsoft Word发表Blog文章的工具
- 关于.Text 0.96
- WHO AM I?看定自己的耕垦区域
- SQL Server首次出现在两个“所有环境”十大排名榜上(该排行包含运行于Microsoft Windows® 和非Windows环境下的所有数据库),这表明SQL Server已经跻身规模最大、行数最多的OLTP数据库之列。
- asp.net上传文件图片的做法
- asp.net默认只允许上传4m的文件,如果上传更大的?
- 水晶报表使用经验谈2--使用sql语句直接生成dataset做为报表的数据源!
- MacroMedia公司的Flex和其开发工具Brady
- 自定义控件时的设计时错误
- 博客园计划增加的功能
- 简单介绍 DocBook
- 几个 WMI 的例子(初级) - 4
- 几个 WMI 的例子(初级) - 1
- 使用WMI获得硬盘的信息
- 能否判断动态数组有没有被分配过?
- Henry的VB.NET之旅(十二)—事件驱动
- Henry的VB.NET之旅(十三)—标准事件处理程序
- Henry的VB.NET之旅(十四)—动态关联事件与处理程序
- Henry的VB.NET之旅(十五)—动态事件处理方法
- Java网络编程3