gpt4 book ai didi

c - C 中的数组匹配

转载 作者:太空宇宙 更新时间:2023-11-04 07:13:22 25 4
gpt4 key购买 nike

在 c 中使用数组传递。在函数 Get_Present_Location() 中定义数组并将其作为指针传递到 main 中,我只是在其中打印它。它似乎工作除了最后一个元素。我得到的不是 -7,而是 0。我可能犯了一个愚蠢的错误,但我不明白为什么。

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

double *Get_Present_Location();

int main(){

double *Present_Point;
Present_Point=Get_Present_Location();

for (int i=0;i<6;i++)
{
printf("Joint[%d] = %f\n",i+1,Present_Point[i]);
}

return 0;
}

double *Get_Present_Location()
{

double point[6]={4,1,5,-3,5,-7}; //Temporary

return &point;
}

最佳答案

您已经回答了自己的问题。

  double point[6]={4,1,5,-3,5,-7};   //Temporary

暂时的(代码也不会在警告打开的情况下编译)

关于c - C 中的数组匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26688481/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com