首页 > 解决方案 > 结构设置和初始化变量

问题描述

我已经提供了代码段部分,设置了结构。设置结构时出现“预期表达式”错误。请参阅我提供的代码段。我已经查看了其他应该可以工作的代码。

 Can not compile the program with the program segment below. Not sure how 
 to correct it. error in the .size and .char part. This part is just the 
 code segment for the structure.


 #define MAX_SIZE 25  // max name size

 typedef struct     // structure for an employee name and height size
 {
    char name[MAX_SIZE];
    int size;
 } Employee;

 int main(int argc, char ** argv)
 {

  Employee student =        // initializes the structure
  {
    .name = { 0 },  // error expected an expression. 
    .size = MAX_SIZE    // error expected an expression.
  };                    // does not accept the .name and .size                           
 }

标签: c

解决方案


我正在使用 Microsoft Visual Studio 2017。


推荐阅读