Developer on Alibaba Coud: Build your first app with APIs, SDKs, and tutorials on the Alibaba Cloud. Read more ＞
#define INF 0x3f3f3f3f 0x3f3f3f3f decimal is 1061109567, that is, 10^9 level (and 0x7fffffff (32-bit int maximum) an order of magnitude), and the general situation of the data are less than 10^9, So it can be used as infinity without the case that the data is larger than infinity.
On the other hand, since the general data is not greater than 10^9, when we add infinity to a data, it does not overflow (this satisfies the "infinity plus a poor number is still infinite"), in fact 0x3f3f3f3f+0x3f3f3f3f= 2122219134, this is very large but not more than the 32-bit int range, so 0x3f3f3f3f also meet our "Infinity plus infinity or infinity" demand.
The biggest benefit: if we want to clear an array, we usually use memset (A,0,sizeof (a)), but when we want to assign an array to infinity (such as the initialization of the adjacency matrix when solving the graph theory problem), you cannot use the Memset function. Because Memset is in bytes, it is able to clear the array 0 because 0 of each byte is 0, now good, if we set infinity as 0x3f3f3f3f, then the miracle happens, 0x3f3f3f3f each byte is 0x3f. So to put an integer array all to infinity, we only need memset (A,inf,sizeof (a))
This article is an English version of an article which is originally in the Chinese language on aliyun.com and is provided for information purposes only. This website makes no representation or warranty of any kind, either expressed or implied, as to the accuracy, completeness ownership or
reliability of the article or any translations thereof. If you have any concerns or complaints relating to the article, please send an email, providing a detailed description of the concern or
complaint, to email@example.com. A staff member will contact you within 5 working days. Once verified, infringing content will be removed immediately.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
and provide relevant evidence. A staff member will contact you within 5 working days.