C++ compile-time expression as an array size -


i'm not sure if term's "array addition".

i'm trying understand following line do:

int var[2 + 1] = {2, 1}; 

how different int var[3]?

i've been using java several years, i'd appreciate if explained using java-friendly words.

edit: thousands of helped me out, occam's razor applies here.

it's not different. c++ allows expressions (even non-constant expressions) in subscripts of array declarations (with limitations; other initial subscript on multi-dimensional array must constant).

int var[];  // illegal int var[] = {2,1};  // automatically sized 2 int var[3] = {2,1};  // equivalent {2,1,0}: not specified 0 int var[3];  // however, no initializer, nothing initialized zero

perhaps code reading writes 2 + 1 instead of 3 reminder trailing 0 intentional.


Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -