c++ - What's the difference between these two memset? -


int color[1001][1001]; int m,n; m=10; n=10; memset(color,0,sizeof(color)); memset(color,0,sizeof(color[0][0])*m*n ); 

what's difference between these 2 memset statements?

any answer highly appreciated. in advance.

what's difference between these 2 memset statements?

the memset function takes, destination, value , count. count sizeof(color) sizeof(int) * 1001 * 1001 first call.

for second sizeof(int) * 10 * 10.

the former clears complete array zeros, while latter partially, starting color[0][0] color[0][99], relies on fact arrays laid out in row-major fashion. relevant excerpt c11 standard (draft n1570), §6.5.2.1 array subscripting:

[…] follows arrays stored in row-major order (last subscript varies fastest).

alternatively, if m = n = 1001 i.e. m , n denote array's dimensions, 2 calls same, just 2 different ways of writing it.


Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -