current position:Home>In C language, the input content is larger than the defined array, but can it be output?

In C language, the input content is larger than the defined array, but can it be output?

2022-02-02 23:13:26 CSDN Q & A

s1 Input more than ten Chinese characters or letters ,s2 It can still output normally , The code is as follows

#include<stdio.h>int main(){ int i=0; char s1[10],s2[10]; scanf("%s",s1); while(s1[i]!='\0'){ s2[i]=s1[i]; i++; } s2[i]='\0'; puts(s2); }

The software used is cfree

img




Refer to the answer 1:

It is possible , As long as the subsequent space has not been allocated to other software
Crossing the border doesn't necessarily collapse , The reason for the crash is that the memory space of the cross-border operation has been used .




Refer to the answer 2:



Refer to the answer 3:

c If the language array is out of bounds, no error will be reported




Refer to the answer 4:

copyright notice
author[CSDN Q & A],Please bring the original link to reprint, thank you.
https://en.primo.wiki/2022/02/202202022313243571.html

Random recommended