Page 121 - C-Language
P. 121

Compound literal having length of initializer


        less than array size specified




         int *p = (int [10]){1, 2, 3};


        rest of the elements of compound literal will be initialized to 0 implicitly.



        Read-only compound literal



        Note that a compound literal is an lvalue and therefore it's elements can be modifiable. A read-
        only compound literal can be specified using const qualifier as (const int[]){1,2}.



        Compound literal containing arbitrary


        expressions




        Inside a function, a compound literal, as for any initialization since C99, can have arbitrary
        expressions.


         void foo()
         {
             int *p;
             int i = 2; j = 5;
             /*...*/
             p = (int [2]){ i+j, i*j };
             /*...*/
         }


        Read Compound Literals online: https://riptutorial.com/c/topic/4135/compound-literals
































        https://riptutorial.com/                                                                               97
   116   117   118   119   120   121   122   123   124   125   126