简体   繁体   English

C的赋值

[英]C assignment of int

When you see code like this in C, what's the order of assignment? 当你在C中看到这样的代码时,分配的顺序是什么?

int i = 0, var1, var2;

I don't understand the syntax... 我不懂语法......

Only i is assigned the value zero. 只有i被赋值为零。

var1 and var2 are uninitialized. var1var2未初始化。

There's no "assignment" in your code whatsoever. 您的代码中没有任何“赋值”。 It is a declaration of three variables of type int , of which one is initialized with zero. 它是int类型的三个变量的声明,其中一个初始化为零。 The = symbol is an integral part of initialization syntax, it has nothing to do with any "assignment". =符号是初始化语法的组成部分,它与任何“赋值”无关。 And since there's only one initialization there, there's really no question about any "order". 由于那里只有一个初始化,所以对任何“订单”都毫无疑问。

If that doesn't answer your question, clarify it. 如果这不能回答你的问题,请澄清一下。

只有一个赋值(i = 0),其余的是定义。

i初始化为0而变量var1var2未初始化,因此具有未指定的值(如果它们在本地范围中定义)。

所有这些都是局部变量,唯一的区别是我被赋值为零,而var1和var2的值是不可预测的,它们将具有垃圾值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM