' '==0

char s=0;
cout<<s;// prints space
if(' '==0){cout<<" space character is equivalent to 0 integer";}
// donot display the message typed ABOVE

DOUBT:when we initialised char s to 0 compiler displayed empty space.it means 0 is equivalent to empty space.
but when we write ' '==0 in if condition it is not displaying what is written inside ,it means space is not equivalent to 0 integer;
but why is this happening ?
is ' ' equivalent to 0????????????
closed account (z05DSL3A)
char s = 0; // Ascii NUL

The Nul character is unprintable (it has not on screen representation) but may be that the cout represents the character as a space.

A space on the other hand has a value of 32 and s a printable character.

1
2
    int x = ' ';
    std::cout << "x = " << x ;


So the nul character and space are not equal.
Topic archived. No new replies allowed.