Anonymous user
Array length: Difference between revisions
→An example why it may be a bad idea in C
Line 530:
=={{header|C}}==
===An example why it may be a bad idea in C===
<p>
The C language uses arrays of a declared size(including variable length arrays,
i.e. VLA) and dynamically allocated memory blocks. While many things are done
the same, the important thing is that the sizeof operator, which returns
a number of bytes, behaves quite differently for arrays and for memory pointers.
Line 540 ⟶ 539:
so even if we define a global variable as an array, after using it as a function
argument the appropriate parameter will "forget" what size the array is.
</p>
<lang C>#define _CRT_SECURE_NO_WARNINGS // turn off panic warnings▼
▲#define _CRT_SECURE_NO_WARNINGS // turn off panic warnings
#define _CRT_NONSTDC_NO_WARNINGS // enable old-gold POSIX names in MSVS
|