Difference between using character pointers and character arrays

前端 未结 9 748
不思量自难忘°
不思量自难忘° 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:15

    Please go through this article below:

    Also see in case of array of char like in your case, char new_str[] then the new_str will always point to the base of the array. The pointer in itself can't be incremented. Yes you can use subscripts to access the next char in array eg: new_str[3];

    But in case of pointer to char, the pointer can be incremented new_str++ to fetch you the next character in the array.

    Also I would suggest this article for more clarity.

提交回复
热议问题