Variable length arrays is a feature where we can allocate an auto array (on stack) of variable size. C supports variable sized arrays from C99 standard. For example, the below program compiles and runs fine in C.
But C++ standard (till C++11) doesn’t support variable sized arrays. The C++11 standard mentions array size as a constant-expression See (See 8.3.4 on page 179 of N3337). So the above program may not be a valid C++ program. The program may work in GCC compiler, because GCC compiler provides an extension to support them.
Student_id : 523 Stud_Name : Sanjayulsha Name_Length: 11 Allocated_Struct_size: 23 Student_id : 535 Stud_Name : Cherry Name_Length: 6 Allocated_Struct_size: 18 Size of Struct student: 12 Size of Struct pointer: 8
This article is contributed by Abhay Rathi and Sanjay Kanna. Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above
- Variable Length Argument in C
- Variable length arguments for Macros
- Can we access global variable if there is a local variable with same name?
- Internal static variable vs. External static variable with Examples in C
- How to print a variable name in C?
- Redeclaration of global variable in C
- Why variable name does not start with numbers in C ?
- How to modify a const variable in C?
- Different ways to initialize a variable in C/C++
- Using a variable as format specifier in C
- C | Variable Declaration and Scope | Question 6
- C | Variable Declaration and Scope | Question 7
- C | Variable Declaration and Scope | Question 8
- C | Variable Declaration and Scope | Question 4
- C | Variable Declaration and Scope | Question 1