pushing to an array

#include <iostream>
#include <vector>

int main() {
    std::vector<int> myVector; // Declaring an empty vector to store integers

    myVector.push_back(3); // Adding the integer value 3 to the end of the vector
    myVector.push_back(7); // Adding the integer value 7 to the end of the vector
    myVector.push_back(11); // Adding the integer value 11 to the end of the vector

    return 0;
}

Explanation:

  • #include <iostream>: Includes the input-output stream header file to perform input and output operations.
  • #include <vector>: Includes the header file for the vector container, allowing the use of vectors.
  • std::vector<int> myVector;: Declares an empty vector called myVector capable of storing integers (int data type).
  • myVector.push_back(3);: Appends the integer value 3 to the end of the myVector vector.
  • myVector.push_back(7);: Appends the integer value 7 to the end of the myVector vector.
  • myVector.push_back(11);: Appends the integer value 11 to the end of the myVector vector.
  • return 0;: Indicates the end of the main() function and returns 0, indicating successful program execution to the operating system.