标签: function-declaration

如何从函数返回指向 char[][][] 的指针?

我有一个static-char 数组定义为:

static const char city_names[1000][4][50];
Run Code Online (Sandbox Code Playgroud)

我想从函数返回一个指向这个变量的指针,我尝试 a static_casttovoid*但它失败了。我怎样才能返回一个指针char[][][]

c++ arrays pointers declaration function-declaration

0
推荐指数
1
解决办法
92
查看次数

无法将“浮动*”转换为“浮动”

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

float array(float a[],int n);

int main() {
    int k=5;
    float a[k+1];
    array(a[k+1],k);
}

float array(float a[],int n )// n = size of array
{
    printf("enter elements in order of increasing:\n");
    for(int i=0;i<n;i++) {
        printf("array[%d]:",i);
        scanf("%f",&a[i]);  
    }
    return a;
}                                   
Run Code Online (Sandbox Code Playgroud)

我想构建一个程序来使用函数给出一个浮点数递增的数组,但它有一个错误,编译器显示这些错误:

[Error] cannot convert 'float*' to 'float' in return9
[Error] cannot convert 'float' to 'float*' for argument '1' to 'float array(float*, int)'
Run Code Online (Sandbox Code Playgroud)

c arrays return-type incompatibletypeerror function-declaration

0
推荐指数
1
解决办法
287
查看次数

使用带有数组参数的函数指针的分段错误

今天我开始学习C,我陷入了函数指针的困境。这是我的代码:

\n

主要.c:

\n
\n#include <stdio.h>\n\nint sumOfElements(int *arr, int arr_elements);\n\nint main()\n{\n\n    int (*ptr)(int,int) = NULL;\n    ptr = sumOfElements;\n    int a[] = {128, 64, 32, 16, 8, 4, 2, 1};\n    printf("Total of price is: %d", ptr(a, 8));\n\n}\n\nint sumOfElements(int *arr, int arr_elements)\n{\n    int k =0;\n    int total;\n    for(;k < arr_elements;k++)\n    {\n        total += arr[k];\n    }\n    return total;\n}\n\n
Run Code Online (Sandbox Code Playgroud)\n

我想做的是访问函数中数组的元素sumOfElements。当我正常调用它时,一切都会顺利。当我尝试使用 时function pointer,编译器之前会向我抛出一些警告,然后是Segmentation Fault错误:

\n
main.c:17:9: warning: assignment from incompatible pointer type [-Wincompatible-pointer-types]                               \nmain.c:19:41: warning: passing argument 1 …
Run Code Online (Sandbox Code Playgroud)

c arrays function-pointers implicit-conversion function-declaration

0
推荐指数
1
解决办法
676
查看次数

所有功能都在IIFE表达式中吗?

如果(function foo(){})是一个表达式,由于'context'为"(括号)"是一个分组运算符,分组运算符只能包含一个表达式.

这导致了这个问题,您能否在IIFE中声明一个函数,或者它仍然算作一个函数表达式?

javascript function function-declaration function-expression iife

-1
推荐指数
1
解决办法
78
查看次数

Perl子例程声明意外符号

我一直在看一些Perl代码,它有一些对我没用的子例程声明.它们显示为:

foo($$$$;$);
foo(\$\$\$);
Run Code Online (Sandbox Code Playgroud)

符号是什么";" 和"\"在这些声明中做或意味着什么?

syntax perl declaration function-declaration

-1
推荐指数
1
解决办法
56
查看次数

在C语言中,函数参数中的双星号**有什么作用

我在链接列表中遇到了一个代码片段,但这是我第一次看到参数中使用“**”双星号。它有什么作用?

// Adding an item to the beginning of the list
void push(node_t ** head, int val) {
    node_t * new_node;
    new_node = (node_t *) malloc(sizeof(node_t));

    new_node->val = val;
    new_node->next = *head;
    *head = new_node;
}
Run Code Online (Sandbox Code Playgroud)

c pointers pass-by-reference function-declaration

-1
推荐指数
1
解决办法
1125
查看次数

有没有更好的方法来编写接受多种类型的C#函数?

一些上下文:我想编写一个类,其中向集合添加内容的主要方法是通过名为Add(或类似的东西)的方法(或方法).所以最好的签名是params object [].在内部,这个函数必须切换/ if-else它可以接受的所有类型.所以,最初它可以接受这个object []数组,但我可能希望看到它也接受object [] []和object [] [] []等,然后方法/函数可以在内部展平,所以在调用此函数之前,用户不需要这样做.

所以...

是否有可能编写一个函数,可以为一种对象接受各种级别的列表类型? 作为一个方面的问题,设计一个接口类,这是更好地接受时object[]IEnumerable<object>params object[](编辑:从问题中解脱出来,因​​为已经有足够的事情了.)

举例来说,我在想,可同时接收/所有的功能object[],IEumerable<object>以及可能进一步嵌套,如:IEnumerable<IEnumerable<object>>,object[][](而上,上和,等等).

这可能吗?

c# generic-collections function-declaration

-3
推荐指数
1
解决办法
868
查看次数

是否有在C中定义函数的特定规则?

我正在编写一个可以处理.c和.h文件的脚本.使用正则表达式我找到给定文件中的所有函数.在我使用CI的过程中,总是以下列方式定义函数:

void foo(int a){
//random code
}
Run Code Online (Sandbox Code Playgroud)

是否可以通过以下方式声明函数:

void
foo(int a){
//random code
}
Run Code Online (Sandbox Code Playgroud)

我总是假设函数类型,名称和参数需要在同一行,但我已被告知,所以我不确定.

c function function-declaration

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

如何在c中将void函数(void)作为参数传递给另一个函数

[在此处输入图像描述][1]我有一个void readline()输出字符串的函数,我想将其作为参数传递给另一个函数,我该怎么做,

谢谢你的帮助。

int scorecount(argc1, argv1, void readline());
void readline();


int main(int argc, char *argv[]){
    scorecount(argc,argv);
}


int scorecount(argc1, argv1, void readline()){

    output a int
    and I want to use the string from readline function somewhere in
    scorecount

}


void readline(){

    output a string

}
Run Code Online (Sandbox Code Playgroud)

c parameters function-call function-declaration

-5
推荐指数
1
解决办法
2473
查看次数