c/ variable-assignment

 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.

Related Question C - Initialize a pointer in a struct How to initialize a struct in C C Initialize Struct with a loop initialize array of struct in c Initialize the struct GHashTable in C Initialize a struct in C Initialize Array of Struct - C initialize struct of C initialize a struct array in c Initialize struct with malloc in C
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM