EmbLogic's Blog

warning on arrays

{

char r[10]=”this is a”;
char d[10]={{‘t’},{‘h’},{‘i’},{‘s’},{‘ ‘},{‘i’},{‘s’},{‘ ‘},{‘a’}};

printf(“string r[10]  %s  size %d\n”,r,sizeof(r));
printf(“single character d[10] %s size %d\n”,d,sizeof(d));

return 0;

}
during compilation it gives warning WHY ?

what wrong i had done in char d[10] ?

warning: braces around scalar initializer [enabled by default]

warning: (near initialization for ‘d[0]’) [enabled by default]

2 Responses to warning on arrays

  1. himanshi says:

    the correction is
    char d[10]={‘t’,‘h’,‘i’,‘s’,‘ ‘,‘i’,‘s’,‘ ‘,’a’};

  2. hemant.kumar says:

    you can initialize when you will be using two_dimensional array e.g..
    int arr[3][3]={{1,2,3},{4,5,6},{7,8,9}};//three rows and three columns.. in the same way you can use character_arrays..
    but in case of 1_D…you should initialize like.. char d[10]=(‘t’,’h’,’s’,’ ‘,’s’,’a’};
    as himanshi has told you..

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>