Assigning an entire array with a single statement

后端 未结 5 1902
闹比i
闹比i 2021-01-11 20:53

Let us say that I declare and initialize

int a[3] = {1, 2, 3};

How can I later asisgn the entire array in one fell swoop? i.e.



        
5条回答
  •  没有蜡笔的小新
    2021-01-11 21:30

    You cannot do that. An array can only be initialized from a brace expression in a declarator-initializer. You assign arrays.

    In C89 there wasn't even such a thing as a "temporary array", though as of C99 these exist by virtue of compound literals (see @Dave's answer).

提交回复
热议问题