指定返回的指针数组来 [英] Assign Returned Pointer to Array

查看:125
本文介绍了指定返回的指针数组来的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个函数返回浮动*它实际上充满作为函数返回一个数组,这样

I have a function returning float* where it's actually filled as an array in the returning function such that

float* some_fnc()
{
    float *x=malloc(sizeof(float)*4);
    x[0]=......
}
...
// in main
float y[4];
y=some_fnc();

不过,我得到一个不兼容类型的错误,是正常的吗?有没有办法来克服这种W / O声明y为浮动*?

however I get an "Incompatible types" error, is it normal? Is there a way to overcome this w/o declaring y as float* ?

推荐答案

您不能修改数组的地址。你为什么不套印Y作为参数传递给some_fnc? (或)你可以只使用浮动指针,如果你只知道在运行时与放大器的大小;不使用数组主。

You cannot modify the address of an array. Why don't you pass y as parameter to some_fnc? (or) you could just use the float pointer if you only knew the size at run time & not use the array in main.

这篇关于指定返回的指针数组来的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆