Why is 49, 50, 51, 52 stored in the array when I declare testArray[] = {'1','2','3','4','5'}? (C programming)

后端 未结 5 1368
醉梦人生
醉梦人生 2021-01-16 01:11

Why is 49, 50, 51, 52 stored in the array when I declare testArray[] = {\'1\',\'2\',\'3\',\'4\',\'5\'}? How should i initialize a string array? Thanks

5条回答
  •  星月不相逢
    2021-01-16 01:32

    Because chars are actually stored as their corresponding value in ASCII.

    You can declare your string as follows:

    char * myString = "String";
    

提交回复
热议问题