Ambiguous if and else branches: Is the behaviour defined?

前端 未结 5 1913
既然无缘
既然无缘 2021-01-18 11:33

I recently came accross some C++ code like the following:

if(test_1)
    if(test_2)
    {
         // Do stuff
    }
    else
       exit(0);
5条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-18 12:16

    It is Defined in C. An else always gets paired with nearest if; therefore you should use proper braces to avoid ambiguity.

提交回复
热议问题