C – 错误:’a’的存储大小是未知的

前端之家收集整理的这篇文章主要介绍了C – 错误:’a’的存储大小是未知的前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
这是我的C程序
  1. #include <stdio.h>
  2.  
  3. struct xyx {
  4. int x;
  5. int y;
  6. char c;
  7. char str[20];
  8. int arr[2];
  9. };
  10.  
  11. int main(void)
  12. {
  13. struct xyz a;
  14. a.x = 100;
  15. printf("%d\n",a.x);
  16. return 0;
  17. }

这是我得到的错误….

按ENTER或键入命令继续

  1. 13structtest.c: In function main’:
  2. 13structtest.c:13:13: error: storage size of a isnt known
  3. 13structtest.c:13:13: warning: unused variable a [-Wunused-variable]

解决方法

你的结构称为struct xyx,但是一个是struct xyz. Once you fix that,the output is 100.
  1. #include <stdio.h>
  2.  
  3. struct xyx {
  4. int x;
  5. int y;
  6. char c;
  7. char str[20];
  8. int arr[2];
  9. };
  10.  
  11. int main(void)
  12. {
  13. struct xyx a;
  14. a.x = 100;
  15. printf("%d\n",a.x);
  16. return 0;
  17. }

猜你在找的C&C++相关文章