首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

关于返回值的不解

2013-01-28 
关于返回值的困惑直接上代码:#include stdio.h#include newCoordinates.hvoid newCoordinates(float *

关于返回值的困惑
直接上代码:

#include <stdio.h>

#include "newCoordinates.h"

void newCoordinates(float * x, float * y, float * farameter)
{
float cos, sin, px, py;//cos 角度值 sin 角度值 x 位移 y位移
float xz,yz;//暂存输出坐标

cos = farameter[0];
sin = farameter[1];
px   = farameter[2];
py   = farameter[3];

xz = cos * *x - sin * *y  - px * cos + py * sin;
yz = (cos * *y + sin * *x + px * sin - py * cos)/(cos * cos - sin * sin);

x = &xz;
y = &yz;
printf("\n%.2f\t%.2f\n",*x,*y);

//return;
}

我把main函数中的x y带入上面函数中,为什么*x *y没有返回到main中呢?
请老师详解缘由。
[解决办法]
因为基本功啊
 *x = xz;
[解决办法]
应该这样:

#include <stdio.h>
#include "newCoordinates.h"
void newCoordinates(float * x, float * y, float * farameter)
{
float cos, sin, px, py;//cos 角度值 sin 角度值 x 位移 y位移
float xz,yz;//暂存输出坐标

cos = farameter[0];
sin = farameter[1];
px   = farameter[2];
py   = farameter[3];

xz = cos * *x - sin * *y  - px * cos + py * sin;
yz = (cos * *y + sin * *x + px * sin - py * cos)/(cos * cos - sin * sin);

//x = &xz;
//y = &yz;
        *x = xz;
        *y = yz;
printf("\n%.2f\t%.2f\n",*x,*y);
}

热点排行