{
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]
the correction is
char d[10]={‘t’,‘h’,‘i’,‘s’,‘ ‘,‘i’,‘s’,‘ ‘,’a’};
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..