Storing a string in an array of chars without the null character

前端 未结 4 1125
走了就别回头了
走了就别回头了 2021-01-14 10:07

I\'m reading the C++ Primer Plus by Stephen Prata. He gives this example:

char dog[8] = { \'b\', \'e\', \'a\', \'u\', \'x\', \' \', \'I\', \'I\'}; // not a s         


        
4条回答
  •  忘掉有多难
    2021-01-14 10:19

    The contents of memory out of bounds is indeterminate. Accessing memory you do not own, even just for reading, leads to undefined behavior.

提交回复
热议问题