Quantcast
Channel: '\0' evaluates false, "\0" evaluates true - Stack Overflow
Viewing all articles
Browse latest Browse all 10

'\0' evaluates false, "\0" evaluates true

$
0
0

Inspired by a program described in K&R section 5.5:

void strcpy(char *s, char *t){    while(*s++ = *t++);}

C program

if ('\0') { printf("\'\\0\' -> true \n"); }else      { printf("\'\\0\' -> false\n"); }if ("\0") { printf("\"\\0\" -> true \n"); }else      { printf("\"\\0\" -> false\n"); }

prints

'\0' -> false"\0" -> true

Why do '\0' and "\0" evaluate differently in C?

clang version 3.8.0


Viewing all articles
Browse latest Browse all 10

Trending Articles





<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>