No out of bounds error

后端 未结 7 666
既然无缘
既然无缘 2020-11-22 01:01

I have this code in C which takes in bunch of chars

#include 
# define NEWLINE \'\\n\'
int main()
{

char c;
char str[6];
int i =         


        
7条回答
  •  隐瞒了意图╮
    2020-11-22 01:44

    Because C/C++ doesn't check bounds.

    Arrays are internally pointers to a location in memory. When you call arr[index] what it does is:

    type value = *(arr + index);
    

    The results are big numbers (not necessarily) because they're garbage values. Just like an uninitialized variable.

提交回复
热议问题