Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can the char type be categorized as an integer?

Tags:

java

c

char

Just now I read "char is the only unsigned integral primitive type in Java." Does this mean the char is one of the integral types in Java?

Same as in C, recently I have read that C types includes scalar types, function types, union types, aggregate types, and scalar types include pointer types and arithmetic types, then arithmetic types include integral types and floating-point types, the integral types include enumerated types and character types.

Can the char type really be categorized as a integer both in Java and C?

like image 377
Victor S Avatar asked Jul 26 '12 14:07

Victor S


People also ask

Can a char be an integer in C?

The char type is an integral type in C, which is in the same family as other integral types such as short , int , long , etc....

Can a char type be a number?

The CHAR data type stores any string of letters, numbers, and symbols.

Why char is Categorised as an integer?

The character data type is often said to be an integer type since all the characters are represented in memory by their associated ASCII Codes. If a variable is declared as char, C++ allows storing either a character or an integer value.

Can an integer be a char in Java?

An integer can be converted into a character in Java using various methods. Some of these methods for converting int to char in Java are: using typecasting, using toString() method, using forDigit() method, and by adding '0'.


1 Answers

Yes, a char is an integral type in all the popular languages in which it appears. "Integral" means that its spectrum is discrete and the smallest difference between any two distinct values is 1. The required range of supported values is usually quite small compared to that of other integral types. Computer hardware traditionally treats integers as the fundamental data type; by contrast, arithmetic floating-point types are a more recent and more complicated addition.

like image 73
Kerrek SB Avatar answered Sep 19 '22 10:09

Kerrek SB