In: Computer Science
True or False: It's easy to loop through an array using a for loop in C++ because you can use the .size() function to get the total number of spaces in the array
True or False: It's easy to loop through a vector using a for loop in C++ because you can use the .size() function to get the total number of spaces in the vector
1.False it is not very easy to loop through an array using a for loop in c++ beacuse we cannot use the .size() function as it is not available in the c++.
code to demonstrate the above statement
#include<bits/stdc++.h>
using namespace std;
int main(){
int a[]={1,2,3,4,5,6};
for(int i=0;i<a.size();i++){
cout<<a[i]<<" ";
}
}
the above code will show an error which is shown below
2.True in vector It easy to loop through a vector using a for loop in C++ because you can use the .size() function to get the total number of spaces in the vector
program to demonstrate the above statement
#include<bits/stdc++.h>
using namespace std;
int main(){
vector<int>v{1,2,3,4,5,6};
for(int i=0;i<v.size();i++){
cout<<v[i]<<" ";
}
}
tje output of the following program will be
If you have any query comment it down and if you like the answer upvote it