C++ Programming Tutorial

Learn modern C++ step-by-step with concise explanations and practical examples. Navigate topics from basics to advanced features using the sidebar.

Arrays and Vectors

C-style arrays have fixed size and no bounds checks. Prefer `std::vector` for dynamic size, safety, and rich APIs.

Array vs Vector
#include \n#include \n\nint main(){\n    int a[3] = {1,2,3};\n    for (int i = 0; i < 3; ++i) std::cout << a[i] << " ";\n\n    std::vector v = {4,5,6};\n    v.push_back(7);\n    for (int x : v) std::cout << x << " ";\n\n    std::cout << " size=" << v.size() << std::endl;\n    return 0;\n}
Tips
  • Use range-based `for` for readability.
  • `std::array` provides a fixed-size array with STL interfaces.

Keep Practicing

Use the online compiler to run examples and test variations. Reinforce learning by building small programs for each topic.