Given: (In C++)
int main () {
int* ptr;
int ary [10][2];
ptr = ary;
return 0;
}
How would I access ary[0][1] with ptr?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
You can’t, because the type of
ptris wrong. The variable should be declared asint(*)[2](pointer to an array of size 2 of integers). Then you could just useptr[0][1].If you must use an
int*, you need to introduce areinterpret_cast. The array indices are laid out like:so you could use
ptr[1]to getary[0][1].