I
Ioannis Vranos
Are the following codes valid?
1.
#include <cstddef>
int main()
{
using namespace std;
int ai[10];
ptrdiff_t d= &ai[10]- &ai[0];
}
2.
#include <cstddef>
int main()
{
using namespace std;
int ai[10];
int *p= &ai[10];
}
I thought both are valid, but I got confused by C++03 regarding vector:
"The elements of a vector are stored contiguously, meaning that if v is
a vector<T, Allocator> where T is some type other than bool, then it
obeys the identity &v[n] == &v[0] + n for all
===> 0 <= n < v.size()".
It says this instead of "0<= n <=v.size()".
1.
#include <cstddef>
int main()
{
using namespace std;
int ai[10];
ptrdiff_t d= &ai[10]- &ai[0];
}
2.
#include <cstddef>
int main()
{
using namespace std;
int ai[10];
int *p= &ai[10];
}
I thought both are valid, but I got confused by C++03 regarding vector:
"The elements of a vector are stored contiguously, meaning that if v is
a vector<T, Allocator> where T is some type other than bool, then it
obeys the identity &v[n] == &v[0] + n for all
===> 0 <= n < v.size()".
It says this instead of "0<= n <=v.size()".