+ 1

Why does C++ need char type if there are already integer?

26th Mar 2018, 3:03 PM
Zack zakariya
Zack zakariya - avatar
2 Réponses
+ 7
char and int differs in size and data range, char is an 8bit data while int (commonly, depending on system architecture and compiler used) is 32bit. Apart from that, an int can't be printed as character without a proper format. Hth, cmiiw
26th Mar 2018, 3:39 PM
Ipang
+ 3
They are completely different. By default there's no string type in c++ but there is libraries for it. You can make a string by using char arrays. char arr[] = "array"; which is equivalent to char arr[5] = {"a", "r", "r", "a", "y", "\0"}; The escaped 0 means that the array is a string and you can output it without a need to loop it cout << arr;
26th Mar 2018, 3:17 PM
Toni Isotalo
Toni Isotalo - avatar