today, I encountered a problem that I have never noticed before, Program :
const char * CP = "some value ";
while (* CP) {
// do something to * CP
++ CP;
}< br> when * CP points to '/0', the program stops. Before that, I always thought '/0' is a space. The output result is a space when '/0' is tested by a useful program. So I started to check the information and found my original idea was wrong.
The ASCII code of '/0' is 0, which is also called in C ++NULL character, The output result is similar to a space with no information. It is not a space;
The test is as follows:
Char A = '/0 ';
Cout <(INT) A <Endl;
If (A = 0)
Cout <"A value is 0" <Endl;
If (A = '')
Cout <"A is a space" <Endl ;;
Cout <"*" <A <"*" <Endl;
I finally found the answer,While ('/0') is equivalent to while (0) (the expression used as a condition statement is automatically converted to the bool type )...,
Null is no problem. You can directly use vs (go to definition) to view the result, that is, 0 (void *) 0; so when int * p = 0, that is, when an empty object is initially started, 0 is forcibly converted to (int *) 0.
therefore, C ++ programmers prefer to use 0 to initialize a pointer variable, instead of using null as a member of the C program .