In C programming, the single-quoted character: 'a' and the double-quoted character: "a" have different meanings.
By placing one character in single quotation marks, you indicate that you want "a" to be interpreted as a single character, so the trailing null byte is not added.
If you must put your character in double quotation marks, it will be declared as a string. In this case, the terminating null byte is automatically concatenated to the end, and you do not need to worry. As a result, the line:
"a/0"
If you want to initialize your str variable in the string "a" using only single quotes, then you will need to explicitly add a terminating null byte.
char str[2]; str[0] = 'a'; str[1] = '/0'; printf("str holds the string %s.", str);
Otherwise, you can simply initialize the first str index to "a" using double quotes, and the terminating null byte will be automatically added to the second index.
char str[2]; str[0] = "a";
source share