Tag: 声明

即使添加了#include ,也会隐式声明popen

这是我的代码的一小部分。 #include #include #include #include #include #include #include #include #include #include #include #include … FILE * pipe; … pipe = popen (“ls /tmp -1”, “r”); … pclose(pipe); blarg.c:106: warning: implicit declaration of function ‘popen’ blarg.c:106: warning: assignment makes pointer from integer without a cast blarg.c:112: warning: implicit declaration of function ‘pclose’ blarg.c:118: warning: assignment makes […]

等价C声明

是 int (*x)[10]; 和 int x[10]; 当量? 根据“顺时针螺旋”规则,它们解析为不同的C声明。 对于点击厌倦: 大卫安德森的“顺时针/螺旋规则” 有一种称为“顺时针/螺旋规则”的技术,可以让任何C程序员在头脑中解析任何C声明! 有三个简单的步骤: 1. Starting with the unknown element, move in a spiral/clockwise direction; when ecountering the following elements replace them with the corresponding english statements: [X] or [] => Array X size of… or Array undefined size of… (type1, type2) => function passing type1 and […]

Calloc用于C中具有负索引的数组数组

我有一个带负索引的数组数组。 它是一个具有实际尺寸[dim_y + 40] [dim_x + 40]的数组,但是用户使用的数据类似于维度[dim_y] [dim_x]。 首先,我有全局,已经定义了维度dim_x,dim_y,所以我有这个 int map_boundaries[dim_y + 40][dim_x + 40]; int (*map)[dim_x+40] = (int(*)[dim_x+40])&map_boundaries[20][20]; 它工作正常。 现在我需要维度dim_y和dim_x是可变的,这意味着我希望数组’map’没有固定大小但是动态,我需要从用户读取dim_y,dim_x和数组’map’是全球性的,所以我有 int **map_boundaries; 我在main()使用calloc map_boundaries = (int **)calloc(dim_y + 40,sizeof(int*)); for(i = 0; i < dim_y + 40; i++){ map_boundaries[i] = (int *)calloc(dim_x + 40,sizeof(int)); } ,但我不知道如何申报第二行 为了更好地理解边界,我在第2条评论中发布了这些内容: http : //everything2.com/title/Negative+array+indexing

为什么允许结构具有“指向其自身类型的指针”作为成员但不允许“(结构类型的数组)”本身?

当我尝试声明以下function时 typedef struct TRIE_NODE { char* word; struct TRIE_NODE node[26]; }TRIE_NODE; 我收到以下错误: ‘struct TRIE_NODE’的定义在结束’}’之前是不完整的 但是,如果我使用指向26个节点的指针声明此函数,它编译就好了。 typedef struct TRIE_NODE { char* word; struct TRIE_NODE* node[26]; }TRIE_NODE; 我想,因为这不是一个实例,所以我不可能得到指向这26个数组中第一个的指针,但如果这就是问题,那么TRIE_NODE* node[26]怎么也不是问题呢? 这个声明不等同于TRIE_NODE node[1][26]吗?

C双字符指针声明和初始化

我总是这样宣告 char *c = “line”; 和…一样 char c[] = “line”; 所以我做到了 char **choices = { “New Game”, “Continue Game”, “Exit” }; 这给了我一个不兼容的指针类型,在哪里 char *choices[] = { “New Game”, “Continue Game”, “Exit” }; 没有。 理解这个有什么帮助吗?

变量的声明如何表现?

#include #include int main(){ char i; int c; scanf(“%i”,&c); scanf(“%c”,&i);// catch the new line or character introduced before x number printf(“%i”,i);// value of that character getch(); return(0); } 程序将以与下一个变量声明相同的方式运行,而不是上述变量声明: 这个: int c; int *x; int i; 或这个: int *x; int c; int i; 并且只有这样: c变量和i变量之前的x指针。 我知道那些最后的声明没有意义, int i而不是char i ,以及一个甚至不需要的添加指针。 但这是偶然发生的,我想知道这是否只是一个巧合。

简单的C数组声明/赋值问题

在更高级别的语言中,我将能够在C中使用类似于此示例的内容,并且它会很好。 但是,当我编译这个C例子时,它会痛苦地抱怨。 如何将新数组分配给我声明的数组? int values[3]; if(1) values = {1,2,3}; printf(“%i”, values[0]); 谢谢。

C中的以下声明有什么区别?

这两个声明之间的区别是什么: char (*ptr)[N]; 与 char ptr[][N]; 谢谢。

C源文件的好处包括它自己的头文件

据我所知,如果源文件需要引用其他文件中的函数,那么它需要包含其头文件,但我不明白为什么源文件包含自己的头文件。 头文件中的内容只是作为每个处理时间的函数声明被复制并粘贴到源文件中。 对于包含自己的头文件的源文件,这样的“声明”对我来说似乎没有必要,实际上,项目在从源文件中删除标题后仍然编译并链接没有问题,所以源文件的原因是什么包括它自己的头?

变量声明和定义

int x; 这是宣言还是定义? 当我写下面的代码时, #include int main(void) { int x; printf(“%p”,&x); return 0; } 它打印一些地址。 因此,在分配内存时, int x; 不能只是一个宣言。 这是一个定义吗?