An example of interference between adjacent variables

zhaozj2021-02-16  49

An example of interference between adjacent variables

2003-5-3

Example of program:

Void main () {char Addra [5], addrb [5]; Printf ("THE ADDRA); Printf (" The Address of Addra [4] IS:% D / N ", & addra [4]); Printf (" THE Address of Addrb IS:% D / N ", & Addrb); Printf (" "The Address of AddrB [4] IS:% D / N", & Addrb [4]); Scanf ("% s", addra); scanf ("% s", addrb); Printf ("AddRA:% S / N", AddRA); Printf ("ADDRB:% S / N", AddRB);}

translater

GNU C

Operating platform:

Win2000

operation result:

the address of addrA is: 2293616the address of addrA [4] is: 2293620the address of addrB is: 2293600the address of addrB [4] is: 2293604abcdabcdefghijklmnopqrstuvwxtyzladdrA: qrstuvwxtyzladdrB: abcdefghijklmnopqrstuvwxtyzl

Some conclusions:

1. The system is sequentially allocated from the high address in the order of the variable.

2, the two variables retain 12 bytes of buffers.

3. The C / C language does not check the boundary of the array, which is the root cause of the error.

转载请注明原文地址:https://www.9cbs.com/read-25048.html

New Post(0)