我有一个static-char 数组定义为:
static const char city_names[1000][4][50];
Run Code Online (Sandbox Code Playgroud)
我想从函数返回一个指向这个变量的指针,我尝试 a static_casttovoid*但它失败了。我怎样才能返回一个指针char[][][]?
#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
今天我开始学习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\nRun Code Online (Sandbox Code Playgroud)\n我想做的是访问函数中数组的元素sumOfElements。当我正常调用它时,一切都会顺利。当我尝试使用 时function pointer,编译器之前会向我抛出一些警告,然后是Segmentation Fault错误:
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
如果(function foo(){})是一个表达式,由于'context'为"(括号)"是一个分组运算符,分组运算符只能包含一个表达式.
这导致了这个问题,您能否在IIFE中声明一个函数,或者它仍然算作一个函数表达式?
javascript function function-declaration function-expression iife
我一直在看一些Perl代码,它有一些对我没用的子例程声明.它们显示为:
foo($$$$;$);
foo(\$\$\$);
Run Code Online (Sandbox Code Playgroud)
符号是什么";" 和"\"在这些声明中做或意味着什么?
我在链接列表中遇到了一个代码片段,但这是我第一次看到参数中使用“**”双星号。它有什么作用?
// 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) 一些上下文:我想编写一个类,其中向集合添加内容的主要方法是通过名为Add(或类似的东西)的方法(或方法).所以最好的签名是params object [].在内部,这个函数必须切换/ if-else它可以接受的所有类型.所以,最初它可以接受这个object []数组,但我可能希望看到它也接受object [] []和object [] [] []等,然后方法/函数可以在内部展平,所以在调用此函数之前,用户不需要这样做.
所以...
是否有可能编写一个函数,可以为一种对象接受各种级别的列表类型? 作为一个方面的问题,设计一个接口类,这是更好地接受时(编辑:从问题中解脱出来,因为已经有足够的事情了.)object[]或IEnumerable<object>或params object[]?
举例来说,我在想,可同时接收/所有的功能object[],IEumerable<object>以及可能进一步嵌套,如:IEnumerable<IEnumerable<object>>,object[][](而上,上和,等等).
这可能吗?
我正在编写一个可以处理.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)
我总是假设函数类型,名称和参数需要在同一行,但我已被告知,所以我不确定.
[在此处输入图像描述][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 ×5
arrays ×3
declaration ×2
function ×2
pointers ×2
c# ×1
c++ ×1
iife ×1
javascript ×1
parameters ×1
perl ×1
return-type ×1
syntax ×1