jeudi 30 janvier 2020

array index 2 is past the end of the array

The string array d[2] should have 3 elements. But it seems that it can contain only 2 elements. The 3rd element is not being stored in the array. What is the reason? Does it have to do anyting with the memory allocation which I have done with the new operator?

#include<iostream>

class A
{
public:
    A()
    {   
        std::string d[2];
        d[0] = "Dilshdur";
        d[1] = "Dilshad";
        d[2] = "Dolon";
        for(int i=0; i<3; i++)
        {
            std::cout<<d[i]<<std::endl;
        }

    }


};


int main()
{
   A *p;
   p = new A;
   return 0;
}

Aucun commentaire:

Enregistrer un commentaire