Get the App
SLTechnology News&Howtos  ›  Development  › 

Example Analysis of Array overflow in C language

Shulou Source: shulou.com Published: 2022-06-03 17:41:29 09月16日 Update

This article mainly shows you the "sample Analysis of Array overflow in C language", which is easy to understand and clear. I hope it can help you solve your doubts. Let me lead you to study and learn the article "sample Analysis of Array overflow in C language".

1. When the length of the array is larger than that defined by us, the length of the array will have the problem of array overflow.

2. When the array overflows, the compiler reports an error at compile time. A normal array overflow means that the extra part of the array is discarded when it is output.

However, if the array overflows as a string, the compiler may pass normally when we still output the array, but the output is not normal. Therefore, when defining arrays and assigning values to arrays, we should be careful to avoid array overflows.

Example

# include#includevoid main () {unsigned char a [3] = {0}; a [0] = 200; a [1] = 200; a [2] = a [0] + a [1]; / / unsigned char value range: 0x255, out of range printf ("aVV% d bRV% d cRV% d\ n", a [0], a [1], a [2]); system ("pause") } / * output: aVERV 200 bRV 200 cRV 144 Please press any key to continue. . . * / above is all the content of the article "sample Analysis of Array overflow in C language". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Arrays examples languages analysis content articles compilation output compiler range length learning help characters strings examples forms times easy to understand more Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB Microsoft vpn Linux Redmi