String initialization with and without explicit trailing terminator

Question :

String initialization with and without explicit trailing terminator,

Answer :

What is the difference between

char str1[32] = "";  

and

char str2[32] = "";  

,

Since you already declared the sizes, the two declarations are exactly equal. However, if you do not specify the sizes, you can see that the first declaration makes a larger string:

char a[] = "a";  char b[] = "a";    printf("%i %in", sizeof(a), sizeof(b));  

prints

3 2  

This is because a ends with two nulls (the explicit one and the implicit one) while b ends only with the implicit one.

Read More  What are the pros and cons of the assorted Java web frameworks?

That’s the answer String initialization with and without explicit trailing terminator, Hope this helps those looking for an answer. Then we suggest to do a search for the next question and find the answer only on our site.

Disclaimer :

The answers provided above are only to be used to guide the learning process. The questions above are open-ended questions, meaning that many answers are not fixed as above. I hope this article can be useful, Thank you