Difference between a string and an array of characters

前端 未结 7 2042
一整个雨季
一整个雨季 2021-02-01 10:18

How are these declarations different from each other?

String s=\"MY PROFESSION\";
char c[]=\"MY PROFESSION\";

What about the memory allocation

7条回答
  •  盖世英雄少女心
    2021-02-01 10:57

    char is a primitive type. String is a class in which actual data is stored internally as a character array

    char c[]="MY PROFESSION";
    

    will give compilation error.

    Character array is the contiguous storage in memory where characters are stored sequentially.

    Check out this Thread for more details.

提交回复
热议问题