I have a struct that contains three int members:
struct ints{
int int1;
int int2;
int int3;
};
I want to access the members of the struct using an int (*)[3]
pointer:
ints i = {1,2,3};
int (*p)[3] = (int (*)[3])&i;
std::cout << (*p)[0] << std::endl;
std::cout << (*p)[1] << std::endl;
std::cout << (*p)[2] << std::endl;
This seems to work fine, but I'm not sure if this is undefined behavior according to the C++ standard. And what if I have a struct with four int members but I still use an int (*)[3]
pointer?