Assign multiple values to array in C

前端 未结 8 1276
无人共我
无人共我 2020-12-01 14:01

Is there any way to do this in a condensed form?

GLfloat coordinates[8];
...
coordinates[0] = 1.0f;
coordinates[1] = 0.0f;
coordinates[2] = 1.0f;
coordinates         


        
8条回答
  •  佛祖请我去吃肉
    2020-12-01 14:28

    Although in your case, just plain initialization will do, there's a trick to wrap the array into a struct (which can be initialized after declaration).

    For example:

    struct foo {
      GLfloat arr[10];
    };
    ...
    struct foo foo;
    foo = (struct foo) { .arr = {1.0, ... } };
    

提交回复
热议问题