Q:

Which order does the else statement follow?

I wanted to be sure about something,
When i have multiple if/else conditions and if does not imply an else condition for one of those if conditions; does the next else statement goes for the last if statement?
For example:
if(condition1)
{
    //operation1
}

if(condition2)
{
    //operation2
}

else
{
    //operation3.  
}

Like above example, if i don't use an else for the first if statement, which if statement does this else work for? Would this cause a problem for me, if i don't specify the else for each if?
I made some tests but wanted to be sure about how does this works actually.

A:

From the Standard, p 6.8.4.1

An else is associated with the lexically nearest preceding if that is allowed by the syntax.

So, in your example, the else pertains to the 2nd if (the one with condition2).

A:

In C (and other C-like programming languages), you can place additional accolades to make statements more clear. Your code is equivalent to:
{
    if(condition1) {
        //operation1
    }
}

{
    if(condition2) {
        //operation2
    } else {
        //operation3.  
    }
}

The else statement is bounded to the second if statement. It means that the program will first evaluate condition1. If condition1 holds, it will execute operation1. Next regardless of the result of the first test, it will test condition2. If condition2 holds, it will execute operation2 and otherwise it will execute operation3. The else always binds with the nearest if (bottom-up) that is not yet bounded that is not yet bounded by an else, or using curly braces as brackets for another binding policy.

