gpt4 book ai didi

c - C语言中如何将数值传递给需要指针值的函数

转载 作者:行者123 更新时间:2023-11-30 21:32:34 25 4
gpt4 key购买 nike

我的函数是void x(int *y);

我想将其命名为 x(&6);x({6});,我不想定义一个整数并将 6 分配给它,我想要单行。

最佳答案

您需要的是compound literals

#include <stdio.h>

void x(const int *y)
{
printf("%d\n", *y);
}

int main(void)
{
x(&(int){6});

return 0;
}

关于c - C语言中如何将数值传递给需要指针值的函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42855624/

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