I need your help in understanding the memset behaviour.
char *data = malloc(40);
memset(data,1,40);
When I saw the data content it was 010101010101010 till the end of the size.Then i changed to this.
memset(data,~0,40);
I saw the correct content as 11111111 till end . What is the difference between the the setting of value as 1 and ~0. thanks for your time.
memsetfills each byte of the provided memory region with the value you specify. Please note that only the least significant byte of the last argument is taken to populate the memory block (even though its type isint).In your first case this byte is 0x01, while int the second case it’s 0xFF (all ones). That’s why you are observing this kind of difference.