Freitag, 28. November 2014

Quick C Tricks - Explicit Declaration Of String Terminator Byte

In C a string is an array of single characters terminated by the NUL-value ('\0'). I came across the following notation to clearly communicate this fact:
// declaring a 10 byte long string buffer which 
// will be later terminated by '\0'
char myString[10+1];
Of couse I could have written the above line like this:
// same thins as above but not that obvious
char myString[11];
It's a cosmetical thing - but they help to improve the readability of your code.

Keine Kommentare:

Kommentar veröffentlichen