Quantcast
Channel: User HolyBlackCat - Stack Overflow
Viewing all articles
Browse latest Browse all 946

Answer by HolyBlackCat for Declaration of dynamic array before getting array length

$
0
0

After trying out different inputs, I found that length is changed to the first input integer, here 4.

What likely happens is that length happens to be zero (keep in mind that reading it is UB due to it being uninitialized, and that's not counting variable-length arrays not being a part of standard C++).

ar then becomes a zero-length array, and accessing a[0] is out of bounds (which is again UB). Apparently length happens to be right after the array in the stack, so it gets overwritten.


Viewing all articles
Browse latest Browse all 946

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>