pointers
Assume the following C variable declaration
int *A [10];
I have a doubt whether A[2][3] is valid or not??
Well it depends on what is at A[2].
For instance, the following would be valid:
1 2 3 4
|
A[2] = (int*) malloc(3 * sizeof(int));
//access A[2][3] (valid)
A[2][3] = 17;
|
while the following would not:
1 2 3 4 5
|
int x = 5;
A[2] = &x;
//access A[2][3] (not valid. undefined behavior)
A[2][3] = 17;
|
Topic archived. No new replies allowed.