gpt4 book ai didi

c - C语言中如何编写 "takes 2 integers, returns a Point_t representing these integers"函数?

转载 作者:行者123 更新时间:2023-11-30 21:42:52 24 4
gpt4 key购买 nike

typedef struct { int x; int y; } Point_t;
Point_t construct_point(int x, int y); /* takes 2 integers,
returns a Point_t representing
these integers */

这个函数怎么写?

最佳答案

这真的很简单:

typedef struct
{
int x;
int y;
} Point_t;

Point_t f(int x, int y)
{
Point_t p = { x, y };

return p;
}

并且(为了预先避免可能的注释):不,这不会返回对局部变量的引用。

关于c - C语言中如何编写 "takes 2 integers, returns a Point_t representing these integers"函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29728698/

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