INFO: Selective Initialization of Array Elements Not Allowed

ID: Q39310


The information in this article applies to:
  • Microsoft C for MS-DOS, versions 6.0, 6.0a, 6.0ax
  • Microsoft C/C++ for MS-DOS, version 7.0
  • Microsoft Visual C++ for Windows, 16-bit edition, versions 1.0, 1.5, 1.51, 1.52
  • Microsoft Visual C++, 32-bit Editions, versions 1.0, 2.0, 2.1, 4.0, 5.0, 6.0


SUMMARY

The ANSI C standard does not allow selective initialization of array elements with the following syntax:


   char MyArray[10] = {'a','b',,'d',,'f','g',,'i','j'}; 
This attempt at selective initialization is not correct and will generate a "Syntax Error" at compile time as follows.
error C2059: syntax error : ','
The following two declarations will compile and are valid declarations for Microsoft C version 5.1 and later:
  1. The initialization of all the elements of the array is as follows:
    
          char MyArray[10] = {'a','b','c','d','e','f','g','h','i','j'}; 


  2. The initialization of the first characters in the array is as follows:
    
          char MyArray[10] = {'a','b','c','d','e'}; 


Additional query words:

Keywords : kbLangC kbVC100 kbVC150 kbVC151 kbVC152 kbVC200 kbVC210 kbVC400 kbVC500 kbVC600
Version : MS-DOS:6.0,6.00a,6.00ax,7.0; WINDOWS:1.0,1.5,1.51,1.52; WINDOWS NT:1.0,2.0,2.1,4.0,5.0
Platform : MS-DOS NT WINDOWS
Issue type : kbinfo


Last Reviewed: July 1, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.