How to initialize a struct in accordance with C programming language standards

前端 未结 15 2917
予麋鹿
予麋鹿 2020-11-21 22:59

I want to initialize a struct element, split in declaration and initialization. This is what I have:

typedef struct MY_TYPE {
  bool flag;
  short int value;         


        
15条回答
  •  执笔经年
    2020-11-21 23:48

    Structure in C can be declared and initialized like this:

    typedef struct book
    {
        char title[10];
        char author[10];
        float price;
    } book;
    
    int main() {
        book b1={"DS", "Ajay", 250.0};
    
        printf("%s \t %s \t %f", b1.title, b1.author, b1.price);
    
        return 0;
    }
    

提交回复
热议问题