【发布时间】:2017-02-06 17:17:34
【问题描述】:
#inlude <stdio.h>
typedef struct node
{
int data, height, count;
struct node *left, *right, *father;
}node;
node *root = NULL;
void main(){
//some code here
}
上面的代码没有错误,但是
#inlude <stdio.h>
typedef struct node
{
int data, height, count;
struct node *left, *right, *father;
}node;
node *root;
root = NULL;
void main(){
//some code here
}
这会产生以下错误:
sample.c:11:1: error: conflicting types for 'root'
sample.c: 10:7 note: previous declaration of 'root' was here
node *root;
^
上述错误在语句时没有重现
root = NULL;
在main function内声明
可能是什么原因?
【问题讨论】:
-
当变量不是初始化的一部分时,您不能只在函数外部分配一个变量。
-
请注意,所有全局变量都是零初始化的,没有必要像你一样将它们重新初始化为零。
标签: c pointers null initialization variable-assignment