Difference between using character pointers and character arrays

前端 未结 9 1175
不思量自难忘°
不思量自难忘° 2020-11-29 03:45

Basic question.

char new_str[]=\"\";

char * newstr;

If I have to concatenate some data into it or use string functions like strcat/substr/

9条回答
  •  孤独总比滥情好
    2020-11-29 04:14

    char new_str[]="abcd";  
    

    This specifies an array of characters (a string) of size 5 bytes (one byte for each character plus one for the null terminator). So it stores the string 'abcd' in memory and we can access this string using the variable new_str.

    char *new_str="abcd";  
    

    This specifies a string 'abcd' is stored somewhere in the memory and the pointer new_str points to the first character of that string.

提交回复
热议问题