David van Dugteren
David van Dugteren

Reputation: 4109

C assignment of int

When you see code like this in C, what's the order of assignment?

int i = 0, var1, var2;

I don't understand the syntax...

Upvotes: 3

Views: 300

Answers (5)

Sachin
Sachin

Reputation: 21921

All of them are local variables , the only difference is i has been assigned a value zero whereas the values of var1 and var2 are unpredictable, they will have garbage values.

Upvotes: 0

Prasoon Saurav
Prasoon Saurav

Reputation: 92874

i is initialized to 0 whereas variables var1 and var2 are uninitialized and thus have unspecified values(if they are defined in a local scope).

Upvotes: 4

Mitch Wheat
Mitch Wheat

Reputation: 300728

Only i is assigned the value zero.

var1 and var2 are uninitialized.

Upvotes: 11

AnT stands with Russia
AnT stands with Russia

Reputation: 320671

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. 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.

Upvotes: 7

srean
srean

Reputation: 2648

There is only one assignment (i=0), the rest are definitions.

Upvotes: 4

Related Questions