【问题标题】:Structure decclaration in c [closed]c中的结构声明[关闭]
【发布时间】:2015-01-03 12:28:06
【问题描述】:
#include<stdio.h>
struct parent{
int a;
int b;
struct child{
char*c ;
} c = {"child"};
} p = {1,2};
void main()
{}

为什么上面的代码会导致编译错误?

【问题讨论】:

  • 因为它是无效的 C 代码并且错误是编译器用来告诉你的方法?
  • 如果上面的代码编译成功,你应该发布一个问题,这将是世界末日的标志。
  • 你想用你的代码获得什么?

标签: c compilation nested structure


【解决方案1】:

写成如下代码

struct parent{
    int a;
    int b;
    struct child{
        char*c ;
    } c;
} p = {1,2, {"child"}};

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-13
    • 2012-11-18
    • 1970-01-01
    • 2018-05-13
    • 1970-01-01
    相关资源
    最近更新 更多