Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

difference between "\0" and '\0'

I am trying to understand following piece of code, but I am confused between "\0" and '\0'.I know its silly but kindly help me out

   #define MAX_HISTORY 20

   char *pStr = "\0";
   for(x=0;x<MAX_HISTORY;x++){
        str_temp = (char *)malloc((strlen(pStr)+1)*sizeof(char));
        if (str_temp=='\0'){
            return 1;
    }
    memset(str_temp, '\0', strlen(pStr) );
    strcpy(str_temp, pStr);
like image 782
Fermi Avatar asked Oct 19 '16 10:10

Fermi


1 Answers

They are different.

"\0" is a string literal which has two consecutive 0's and is roughly equivalent to:

const char a[2] = { '\0', '\0' };

'\0' is an int with value 0. You can always 0 wherever you need to use '\0'.

like image 172
P.P Avatar answered Oct 08 '22 16:10

P.P