Memset on assignment (selection of maximum value minimum value)

memset assigned assignment is assigned ASSCII binary code into
such memset (, 0xff, sizeof () ), 0xff into binary 11111111, int is 4 bytes it finally 11111111111111111111111111111111 -1. (Into a binary fill the seats, then the assignment).
The OIER usually want to be able memset assigned to the array by a maximum of
## how to define the infinite
this mainly to see the data range.
If the direct use int or maximum value and the maximum value of the same digit as infinite words
such as + 999 2147483647
burst int, it becomes negative infinity from infinity we define, which does not meet our expectations.
So in the end that what used to when this - infinity
often see big brother Ben ah ah God would use:
memset (, 0x3f, sizeof);
under specially to try, and found 0x3f3f3f3f really is a very delicate constants
his decimal is 1061109567 i.e. 10 ^ 9 levels (and 0x7fffffff an order of magnitude), as a Oier, topic data in the general case is smaller than 10 ^ 9, it can be used as an infinite use without case data is greater than infinity occurs
because 0x3f3f3f3f each byte is 0x3f! So take some memory all set to infinity, we just need to memset (a, 0x3f, sizeof ( a)) (memset assignment in bytes).

所以在通常的场合下,0x3f3f3f3f真的是一个非常棒的选择。

其他常用赋值:

memset(arr,0x7F,sizeof(arr)); //它将arr中的值全部赋为2139062143,这是用memset对int赋值所能达到的最大值

memset(arr,0x80,sizeof(arr)); //set int to -2139062144 //赋负值

给double赋值:
memset(arr,0x7F,sizeof(arr)); //set double to 1.38242e+306
memset(arr,0xFE,sizeof(arr)); //set double to -5.31401e+303

Guess you like

Origin www.cnblogs.com/heanda/p/11330009.html