zero an array inside a struct in c++ -


this question has answer here:

i have struct defined in program.

struct a{     int arr[10]; } 

lets have pointer it. a * = new a;

i can 0 in 2 ways:

memset(&a->arr,0,sizeof(a)); memset(a->arr,0,sizeof(a)); 

both work , same!

which 1 more correct?

this correct way array

memset(a->arr,0,sizeof(a->arr)) 

picked out arr member in case there other structure members not need touched. makes no difference in example following likewise

memset(a->arr,0,sizeof(a)); 

Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -