Click here to Skip to main content
14,984,032 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
when to terminate the looping through a string using the statement
text[i] != 0
? and when to terminate it using the statement
text[i] != '\0' 

What I have tried:

Updated 23-Jun-21 2:17am

There is no difference. '\0' and 0 are just different ways of expressing zero.
The choice between them is a matter of coding style.
The '\0' form is more clearly a character value, but the compiled code would be identical.
Ahmad Qassym 23-Jun-21 16:54pm
They are equivalent. Moreover they are equvalent to
It depends on your personal taste.
A developer used to C++ would probably use the second one.
Ahmad Qassym 23-Jun-21 16:54pm
CPallini 26-Jun-21 5:13am
You are welcome.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900