Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9079785
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T19:55:05+00:00 2026-06-16T19:55:05+00:00

Need help.. Please tell me why A.clear() does not clear the first column too?

  • 0

Need help.. Please tell me why ” A.clear() ” does not clear the first column too?
………………………………………………..

#include <iostream>
#include <vector>
using namespace std;

int N, M;
vector< vector<int> > A;
int main()
{
    cin >> N >> M;
    A.resize(N + 2);
    for (int i = 0; i <= N; ++i)
    {
        A[i].resize(M + 2);
    }
    A.clear();
    for (int i = 0; i <= N; ++i)
    {
        for (int j = 0; j <= M; ++j)
        {
            cout << A[i][j] << ' ';
        }
        cout << '\n';
    }
    return 0;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T19:55:07+00:00Added an answer on June 16, 2026 at 7:55 pm

    clear removes all elements of the vector as opposed to setting all of them to 0 as you seem to be expecting. After calling clear the size of your vector is 0. Thus when you try to read A[i][j] you are accessing an index out of bounds and anything may happen(your code causes undefined behavior).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please i need your help with how to include INDEXES in my tables, i've
I am using core-plot but i need to use any other api? please help
guys i need your help, please tell me how can i pass 2 different
I need help in hovering two HTML tags at once. Please tell how it
I need a little help here please.What am trying to do is pull all
Please i need help, this code below works fine on my localhost, php5.3+ but
Please, I need help with my code: def start(): def start_tkinter(): global main,l main.destroy()
Need some help, please. I have a line of horizontal thumbnails loaded as ONE
Please I need your help with grabbing rows from a table and dynamic text
Please help! I need to produce a Crystal Report with multiple data columns, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.