0

Why memset works for -1 but not for 5?

https://code.sololearn.com/cg7YyS9Sozu4/?ref=app

18th Oct 2020, 5:50 AM
[ ]
[     ] - avatar
3 Antworten
+ 4
memset sets each byte to the byte n. An int has 4 bytes on a non 16-bit machine so it gets the byte "0000 0101" (5) 'encoded' in it 4 times. "0000 0101 0000 0101 0000 0101 0000 0101" = 84 215 045 It just so happens to work with -1 because "1111 1111 1111 1111 1111 1111 1111 1111" = -1
18th Oct 2020, 8:55 AM
Dennis
Dennis - avatar
18th Oct 2020, 7:17 AM
[ ]
[     ] - avatar
0
Thanks Dennis
18th Oct 2020, 9:26 AM
[ ]
[     ] - avatar