如何返回一个浮点阵列 [英] How to return an floating point array

查看:74
本文介绍了如何返回一个浮点阵列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要创建一些浮动点的数组的功能。

I need a function that creates an array with some floating points.

double * my_function( )
{
    static double arr[10] = {20, 21, 22, 23, 24, 25, 26, 27, 28, 29};

    return arr;
}


int main ()
{
    double *first_pos;
    int i;

    first_pos = my_function();
    for ( i = 0; i < 10; i++ )
    {
        printf( "%d", *(first_pos + i));
    }

return 0;
}

本打印一些随机的数字。

This prints some "random" numbers.

我是一个困惑的指针/阵列!

I'm a confused about pointers/arrays!

推荐答案

您指针/数组用法是好的。

Your pointer/array usage is fine.

printf("%f", *(p + i));

打印与%F 说明一倍。 %d个是整数。

这篇关于如何返回一个浮点阵列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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