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

后端 未结 5 1347
醉梦人生
醉梦人生 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:25

    If you wanted an array of numeric values, it should have been initialized as {1,2,3,4,5}. Putting the numerals in single quotes means they are characters, and the 49, 50, 51,... you are seeing are the ASCII codes for the characters '1', '2', '3', '4'.

提交回复
热议问题