Main()是否接受表达式?

Arp*_*pit 0 c++ program-entry-point

为什么此代码打印1而不是5

码:

main(int x=5) //this defn. is written intentionally to chec weather main accepts 
                expression or not. 
{
 printf("%d",x);  
}
Run Code Online (Sandbox Code Playgroud)

编译使用:minGW 3.2

编辑

我的观点是天气x=5执行与否.如果没有那么为什么我没有得到任何错误或警告.

Kev*_*imm 10

因为x实际上是argc(并且你的参数计数是1)

main的签名是:

int main (int argc, char **argv)
Run Code Online (Sandbox Code Playgroud)

argc是参数计数,
argv是这些参数的数组

  • @Arpit:用足够的参数调用程序,否则......`printf("%d",5);`? (4认同)
  • @Arpit当然不是.你使`argc`有一个默认值('5`)但是`argc`总是*传递给`main`.你的'5`永远不会被使用. (4认同)