相关疑难解决方法(0)

在函数调用的参数内定义新函数,数组,结构等

如果你有一个功能,采取以下措施:

void foo(char **arr);
Run Code Online (Sandbox Code Playgroud)

你怎么能做到以下几点:

void foo(char* x[] = { "hello", "my", "friend" });
Run Code Online (Sandbox Code Playgroud)

如果这让您感到困惑,那么在Java中我们通过以下方式实现此目的:

public void foo(String[] x);

foo(new String[] { "hello", "my", "friend" });
Run Code Online (Sandbox Code Playgroud)

目前,我在C中做了以下我讨厌,因为它看起来很丑:

char* myArr[] = 
    { 
        "hello", "my", "friend"
    };

foo(myArr);
Run Code Online (Sandbox Code Playgroud)

c arrays pointers function compound-literals

3
推荐指数
2
解决办法
87
查看次数

标签 统计

arrays ×1

c ×1

compound-literals ×1

function ×1

pointers ×1