+ 1
Why the size of s2 array is 8 ????
int x, y; char s1[] = "Sololearn"; char s2[] = {'S', 'o', 'l', 'o', 'q', 'u', 'i', 'z'}; x =sizeof(s1); y = sizeof(s2); printf("%d, %d",x, y); O/P :- 10,8
7 odpowiedzi
+ 1
if you store the array inside curly braces the contents of the array will be the ones you say it to be
+ 2
Actual strings have an enclosing NULL character (\0), so that's why the first one it's bigger. The second is just an array of characters
+ 2
because it contains 8 characters
+ 2
Bebida Roja, so when we store string in array during declaration time with every character in single quote the string does not contain any null character? Please just confirm this, I will be happy then .
+ 1
Airee you mean the second one has no null character in last ??
+ 1
yes, any string within double quotes will contain a null terminating character, thats why the first one has size 10, but your question was about the second string.
+ 1
Babida Roja, Thanks man