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

  • Home
  • SEARCH
  • 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 8822369
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T06:05:32+00:00 2026-06-14T06:05:32+00:00

Why does the last expected output differ from the actual output in the following

  • 0

Why does the last expected output differ from the actual output in the following code?

#include<iostream>
#include<fstream>
#include<istream>
#include<sstream>
#include<vector>

using namespace std;


int main()
{
        vector<int> v;
        for(int ii = 0; ii < 4; ii++){
            v.push_back(0);
        }

        vector<vector<int>> twoDv;

        for(int ii = 0; ii < 5; ii++){
            twoDv.push_back(v);
        }

        cout<<"Expected Output : " << &twoDv[0][0] <<'\t'<< (&twoDv[0][0] + 3) <<'\t'<< (&twoDv[0][3] + 1)<<'\n';
        cout<<"Actual Output   : " << &twoDv[0][0] <<'\t'<< &twoDv[0][3] <<'\t'<< &twoDv[1][0] << '\n';
}
  • 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-14T06:05:34+00:00Added an answer on June 14, 2026 at 6:05 am

    The standard doesn’t say that &twoDv[1][0] is equal to &twoDv[0][3] + 1. It says that &twoDv[1] is equal to &twoDv[0] + 1, and that &twoDv[0][1] is equal to &twoDv[0][0] + 1.

    Suppose for a moment that &twoDv[1][0] were equal to &twoDv[0][3] + 1, and then you did twoDv[0].resize(5);. Suddenly we have a conflict, &twoDv[0][3] + 1 can’t be the address of &twoDv[1][0] and also the address of &twoDv[0][4]. So the resize operation on twoDv[0] would have to invalidate iterators and references to the elements of another vector twoDv[1]. This would be very undesirable behavior.

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

Sidebar

Related Questions

Why does the below code give Seg. Fault at last line? char* m=ReadName(); printf(\nRead
I copy stuff from output buffers into C++ code I'm working on in vim.
This SELECT finds Kelly as expected: select [First Name], [Last Name], Phone from [Data$]
I was experimenting with regexps last day and the following code gave me quite
I expected A::~A() to be called in this program, but it isn't: #include <iostream>
Considering the boundaries of a List are known, does .Last() enumerate the collection? I
What does the last function argument mean in C language? Please, point to documentation
Does anyone know of a way to detect when the last time a Microsoft
Does anyone know how to test for the first member and last member in
Does SQL Server 2005 maintain built-in, queryable, row-level last-modified timestamp metadata? I'm doing some

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.