0

In a book I am reading the author has code char initial[2] = {0}; What does this mean? I didn't think char could be promoted also not to an int?

Jinzu
  • 1,325
  • 2
  • 10
  • 22
  • `char` is an integer type and can be assigned the value `0`. Also a character such as `'a'` is an `int` type, not `char`. – Weather Vane Aug 09 '19 at 21:43
  • In C, `char` means 8-bit integer. – Barmar Aug 09 '19 at 21:47
  • @Barmar - Not necessarily 8-bit; rather "_Smallest addressable unit of the machine that can contain basic character set._", but an integer nonetheless. For TI C2000 DSP's for example a `char` is 16 bit because that is the smallest addressable unit in that architecture. – Clifford Aug 09 '19 at 22:22
  • _"I didn't think char could be promoted also not to an int?"_ - it certainly can, but that has little to do with the question; nothing is being "promoted" here. Rather there is an _implicit conversion_ from int to char. In C a char is simply a "small" integer. – Clifford Aug 09 '19 at 22:24
  • @Clifford If I were writing a full answer I would have said something like "at least 8-bit integer", I didn't feel the need to go into detail in a throwaway comment. – Barmar Aug 09 '19 at 22:26
  • @Barmar It is possible to be both succinct and accurate. The point would have been served perhaps simply by "char in an integer type” - size is irrelevant to the point you were making. – Clifford Aug 11 '19 at 17:55

0 Answers0