fork download
  1. #include <stdio.h>
  2.  
  3. struct test{
  4. char field[16];
  5. };
  6.  
  7.  
  8. int main(int argc, char * argv[]){
  9. const char *string = "some string";
  10. struct test t1 = {.field = *string};
  11. struct test t2 = {.field = string};
  12. struct test t3 = {.field = "some string"};
  13. struct test t4 = {{'s', 'o', 'm', 'e', ' ', 's', 't', 'r', 'i', 'n', 'g', '\0'}};
  14.  
  15.  
  16. printf("t1::field = %s\n", t1.field);
  17. printf("t2::field = %s\n", t2.field);
  18. printf("t3::field = %s\n", t3.field);
  19. printf("t4::field = %s\n", t4.field);
  20. }
Success #stdin #stdout 0s 9424KB
stdin
Standard input is empty
stdout
t1::field = s
t2::field = 4
t3::field = some string
t4::field = some string