用int a表示vector的size在if语句中判断结果不一样?

vector int prices;
if (n < prices.size() - 3 && prices[n] <= prices[n + 1]) {
cout << "1";
}
prices.size=2,n=1时不会因为 n < prices.size() - 3 而跳过后续,而数组越界报错。

但先用一个数表示出来就不会
int a = prices.size()-3;
if (n < a && prices[n] <= prices[n + 1]) {
cout << "1";
}
成功运行

img


我这里都正常,没有出现越界的情况