lundi 4 mars 2019

Why does this code not throw an exception in C++?

I saw this on Quora, the code goes something like this:-

#include <iostream>
int main()
{
   int a[3] = {10, 11, 12};
   std::cout << 2[a] << '\n';
   return 0;
}

Why does this not throw an exception?

Note:- What I think is that each object has a common copy of functions and because of that, the compiler chooses to store those functions somewhere even before the objects are instantiated. (?). So basically, when we instantiate the class with a null pointer, it still has that function pointer it can call to and hence this runs. Is my intuition correct?

Aucun commentaire:

Enregistrer un commentaire