arr[n] == 1 -> this code contains error
but the code below works well
Im curious that computer compute(n < arr.size()) and think arr[n] == 1 code doesn't have to compute because (n < arr.size() && arr[n] == 1) is false whether arr[n] == 1 is true or false.
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int n, x;
vector<int> arr;
int main() {
arr.push_back(1);
arr.push_back(1);
arr.push_back(1);
int n = 3;
if (n < arr.size() && arr[n] == 1) {
cout << 1;
}
}
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int n, x;
vector<int> arr;
int main() {
arr.push_back(1);
arr.push_back(1);
arr.push_back(1);
int n = 3;
if (n < arr.size()) {
if (arr[n] == 1) {
cout << 1;
}
}
}
i want to know the difference between upper code and lower code thankx