Difference Between...

What is the difference between 0 and "0"? I don't even think there IS any. Such as, if we declare a variable's data to 0, it still works, as variables don't allow numbers in their names. So even if we consider it a string literal, will it even be DIFFERENT? I have got no idea. Thanks
closed account (o3hC5Di1)
Hi there,

I do think there is a difference, the difference is in the datatype.
(Someone please correct me if I got this wrong)

1
2
3
0 //this is a constant int
"0" //this is a constant string
'0' //this is a constant char 


I would suggest you don't start forming opinions on what you think "is" or "isn't" until you have a better grasp of the language.
Some things in programming may seem illogical from a human perspective, but when seen from the computers perspective (in 1's and 0's) it usually makes sense.

Hope that helps.

All the best,
NwN
variables don't allow numbers in their names


News to me.
closed account (zb0S216C)
john924xps wrote:
"What is the difference between 0 and "0"?"

A big difference. 0 is a constant signed integral literal. "0" is a pointer to a constant character (const char *). The difference here is that "0" has an address, whereas 0 does not. As a result, unless a string is placed at the memory location 0x0, 0 and "0" will never be equal.

NwN wrote:
'0' //this is a constant char

That's a constant integer.

Wazzak
Last edited on
That's a constant integer.


It's actually treated as a char by the language. Of course you can assign it to an integer, but for purposes of type identification, '0' is a char, not an int.
Topic archived. No new replies allowed.