18, constant in the function parameters

xiaoxiao2021-03-06  81

-----------

For some pointer parameters in some functions, if read-only in the function, use const to modify it, so that others will know when you read your function interface, you will know that your intent is [in], if not When constant, the parameter represents [IN / OUT], pay attention to the Const use in the function interface, which is conducive to the maintenance of the program and avoids some errors.

Although const char * p, const char * p, there is no, because your statement is not constant, the content of the pointer can be changed, because the compiler will force the conversion, but plus such a Description, facilitating the reading and compilation of the program. Because in C, a Warning will be reported when modifying the memory pointed to by a const pointer. This will cause the programmer's attention.

C is very strict, so much more use of C , using const, constant member functions, constant variables, which will make your code and your program more complete and easy to read. (I will not say more about C constant)

转载请注明原文地址:https://www.9cbs.com/read-107731.html

New Post(0)