I just started learning C and am rather confused over declaring characters using int and char.
I am well aware that any characters are made up of integers in the se
The char
type has multiple roles.
The first is that it is simply part of the chain of integer types, char
, short
, int
, long
, etc., so it's just another container for numbers.
The second is that its underlying storage is the smallest unit, and all other objects have a size that is a multiple of the size of char
(sizeof
returns a number that is in units of char
, so sizeof char == 1
).
The third is that it plays the role of a character in a string, certainly historically. When seen like this, the value of a char
maps to a specified character, for instance via the ASCII encoding, but it can also be used with multi-byte encodings (one or more char
s together map to one character).