typedef struct Node{
int x;
int y;
struct Node* next;
}Node;
i want create in main "list" in this way:
int main(){
Node list;
}
and not in this way:
int main(){
Node list = {1,2,NULL};
}
i want initialize a struct in declaration of struct tryed this way:
typedef struct Node{
int x;
int y;
struct Node* next;
}Node = {1,2,NULL};
error C2513: 'Node' : no variable declared before '='
need help
您不能在C中为结构成员提供预定义的值。请使用类似构造函数的函数或类似构造函数的宏。
The typedef (or struct) "statement" defines a type, not an object.
Types have no value. It only makes sense to speak of values in relation to objects.
Objects do not have a default value (other than 0
when they're implicitly initialized).
So you can't do what you want.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.