首页 > 解决方案 > 为什么这段代码在没有 int main() 的情况下运行

问题描述

#include <stdio.h>
int main()
struct books
{
char title[50];
char author[50];
char sub[100];
int b_id;
};

//here int main should be used but not still the code runs fine why??

{
struct books b1={"48lop","rg","sh",288017};
printf("%s\n",b1.title);
printf("%s\n",b1.author);
printf("%s\n",b1.sub);
printf("%d",b1.b_id);
return 0;
}

标签: cstructure

解决方案


这是因为您使用的是 k&r 语法。

您不使用 ANSI C 语法。


推荐阅读