简体   繁体   中英

What does var[x] do?

关于 c 变量,我想知道 x 在做什么:

int var[x]

This is a declaration of a Variable Length Array (VLA).

The value of expression x (most likely, a variable) is treated as the number of array elements. It must have a positive value at the time the expression is evaluated, otherwise the declaration of the VLA produces undefined behavior.

The int defines the type of the variable, the [] defines the variable as an array, the number in the [] says the number of elements in the array. Int var[4] sets var as an array of 4 ints So, after that, var[0] is the first element, var[1] the second and var[3] the last one (index starts in 0 as you can see)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM