Reputation: 799
Instead of this -
if(*condition1*){
*statement/s*
}
else if(*condition2*){
*some different statement/s*
}
if this is used -
if(*condition1*){
*statement/s*
}
else
if(*condition2*){
*some different statement/s*
}
Does the compiler sees both of these as same things, because white-space does not matter in C, and the 2nd if
gets associated with the else
statement.
Similarly, for this, do they mean the same?
for(*initialization*;*condition*;*increment*)
;
and this -
for(*initialization*;*condition*;*increment*);
where ; is a null statement.
If yes, then why?
Upvotes: 1
Views: 67
Reputation: 734
The else if
conditions are same.
but the for loop is different, because,
for(*initialization*;*condition*;*increment*)
;
here before the ; you can give the statements to execute and it will be executed. but if you specify the ; without the statements then if the condition is true nothing will be done.
Upvotes: 1
Reputation: 37023
Yes both if and for statements are the same. For C, Space, newline doesn't matter.
Upvotes: 2
Reputation: 14511
Yes. Whitespace (apart from its presence at all) truly is insignificant in C. Most C implementations collect whitespace while lexing.
Upvotes: 1