“Ukuran vektor” Kode Jawaban

ukuran vektor c

#include <vector>

int main() {
  std::vector<int> myVector = { 666, 1337, 420 };
  
  size_t size = myVector.size(); // 3
  
  myVector.push_back(399); // Add 399 to the end of the vector
  
  size = myVector.size(); // 4
}
Bright Badger

Ukuran vektor

#include<iostream>
#include<vector>
using namespace std;
int main(){
  //Creation of integer vector
  vector<int> vectorArray {1,2,3,4,5,6,7,8,9};
  //Created vector has 9 elements on it 
  int sizeOf_vectorArray= vectorArray.size();
  
  cout<<sizeOf_vectorArray; // Output will be 9
  
  vectorArray.push_back(10); // 10 will be added in the end of the vector
  
  sizeOf_vectorArray=vectorArray.size();
  
  cout<<sizeOf_vectorArray; // Output will be 10
  
  vectorArray.push_front(0); //0 will be added in the begining of the vector
  
  sizeOf_vectorArray=vectorArray.size();
  
  cout<<sizeOf_vectorArray; // Output will be 11
  
  return 0;
} 
Manaj Bera

Ukuran vektor c

size() function is used to return the size of the vector container or the number of elements in the vector container.
using namespace std;
int main(){
    vector<int> myvector{ 1, 2, 3, 4, 5 };
    cout << myvector.size();
    return 0;
}
//Output = 5
Sleepy Head

Jawaban yang mirip dengan “Ukuran vektor”

Pertanyaan yang mirip dengan “Ukuran vektor”

Lebih banyak jawaban terkait untuk “Ukuran vektor” di C++

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya