C++ array initialization

前端 未结 4 1944
Happy的楠姐
Happy的楠姐 2020-12-02 06:26

is this form of intializing an array to all 0s

char myarray[ARRAY_SIZE] = {0} supported by all compilers? ,

if so, is there similar syntax

4条回答
  •  误落风尘
    2020-12-02 06:47

    You can declare the array in C++ in these type of ways. If you know the array size then you should declare the array for: integer: int myArray[array_size]; Double: double myArray[array_size]; Char and string : char myStringArray[array_size]; The difference between char and string is as follows

    char myCharArray[6]={'a','b','c','d','e','f'};
    char myStringArray[6]="abcdef";
    

    If you don't know the size of array then you should leave the array blank like following.

    integer: int myArray[array_size];

    Double: double myArray[array_size];

提交回复
热议问题