c++ - Casting a (pointer to a variable sized array) to (pointer to pointer) -


what happens when cast [pointer variable sized array] [pointer pointer] ?

int ar[r][c]; int **ptr = (int**)ar;  // implicit casting not allowed ptr[0][0] = 100; 

the above code gives runtime error.

casting variable sized array pointer works expected:

int ar[c]; int *ptr = ar; ptr[0] = 100; 

here ar decays pointer first element.

but happens internally when casting int(*)[c] int**? why result in runtime error when reading/writing int** variable?

the problem ptr[0] or *ptr supposed pointer, not. is, ptr[0] or *ptr not contain valid pointer. @ address there first element of array ar. run-time error when use expression ptr[0][0] in general case program behaviour undefined.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -