Tag: 声明

为什么在运行期间c中接受?

为什么我们可以在c中这样做? int n; scanf(“%d”,&n); int a[n]; 我认为数组在加载时间内位于内存中,但似乎上述示例在运行时期间有效。 我是否误解了任何事情? 你们能帮忙吗? 谢谢,

C函数声明在另一个函数内

任何人都可以向我解释这些问题: int xyz( void ) { extern void abc( void ); } 函数定义中的函数声明? 还是我想念一些东西?

function指针声明 – __P做什么?

通常的函数指针定义forms是: int function(int, int); int (*ptr)(int, int); 但我今天看到一张我不明白的表格。 有人能解释一下吗? int (*close) __P((struct __db *));

这些声明在C中有什么区别?

在C和C ++中,以下声明有什么作用? const int * i; int * const i; const volatile int ip; const int *i; 上述任何声明是否有误? 如果没有,它们之间的含义和区别是什么? 上述声明有什么用处(我的意思是我们必须在C / C ++ / embedded C中使用它们)?

为什么在编程中使用常量?

我刚刚回过头来学习使用Ivor Horton的Beginning C书。 我对于声明常量似乎与同一句子中的变量混淆了一点。 只是为了澄清一下,在C中指定常量和变量有什​​么区别,实际上,何时需要使用常量而不是变量? 我知道人们说在程序执行期间信息没有改变时使用常量,但我真的不能想到不能使用变量的时候。

声明与global,local和static同名的变量

我有以下代码片段,我必须分析输出将是什么: #include void f(int d); int a = 1, b = 2, c = 3, d = 4; int main(){ int a = 5, c = 6; f(a); f(b); f(c); printf(“%d %d %d %d\n”,a,b,c,d); return 0; } void f(int d){ static int a = 0; a = a + 7; b = a + d; […]

struct typedef中的声明规则

我正在阅读’C编程语言’,并遇到了关于struct的 typedef的问题。 代码是这样的: typedef struct tnode *Treeptr; typedef struct tnode { /* the tree node: */ char *word; /* points to the text */ int count; /* number of occurrences */ struct tnode *left; /* left child */ struct tnode *right; /* right child */ } Treenode; 到我们写的时候 typedef struct tnode *Treeptr; tnode仍未声明,但我们没有得到任何编译错误,但是当我们将上面的语句更改为: typedef Treenode […]

在范围的开头声明C89局部变量?

我试图在ANSI C中这样做: include int main() { printf(“%d”, 22); int j = 0; return 0; } 这在Microsoft Visual C ++ 2010(在ANSI C项目中)不起作用。 你收到一个错误: error C2143: syntax error : missing ‘;’ before ‘type’ 这确实有效: include int main() { int j = 0; printf(“%d”, 22); return 0; } 现在我在许多地方读到你必须在变量存在的代码块的开头声明变量。这通常适用于ANSI C89吗? 我找到了许多人们提出这个建议的论坛,但我没有看到它写在任何“官方”来源,如GNU C手册。

为什么这个逗号的使用在表达式中起作用但在声明中失败?

来自高级OOP语言C#和Java,最近开始在C中摸不着头脑。我觉得C有点奇怪,就像有人觉得JS一样。 所以想澄清如下: 下面给出了错误,这看起来很直观,因为即使在OOP语言中它看起来像是不正确的语法 int i=0,1,2; /* Error : expected identifier or ‘(‘ before numeric constant int i = 0, 1, 2; ^ */ 但是下面的工作令人惊讶: int i; i = 0,1,2; //works 为什么会这样? 他们保持这种行为或仅仅解析一些技术问题是否有意义?

具有旧样式函数的C编译器的行为,没有原型

当我的程序包含两个文件时: main.c中 #include int main(void) { printf(“%lf\n”,f()); return 0; } func.c double f(int a) { return 1; } 编译器不显示任何错误。 当我的程序只包含一个文件时: main.c中 #include int main(void) { printf(“%lf\n”,f()); return 0; } double f(int a) { return 1; } Visual C ++ 2008编译器显示以下错误: Error 2 error C2371: ‘f’ : redefinition; different basic types d:\temp\projects\function1\function1\1.c 8 function1 任何人都能解释这种奇怪的行为吗?