answersLogoWhite

0


Best Answer

Because a character is an integer, not a real number. You probably meant int rather than integer, but no implementations of C++ treat a char as an int. All implementations are guaranteed to evaluate sizeof(char) as being exactly 1 (byte). Moreover, a string of 4 characters will occupy exactly 32-bits, not 128-bits (assuming an int is 32-bits, which is entirely dependant upon the implementation).

When processing single characters the CPU will treat them according to the system's word length (which is 32 bits on a 32-bit machine), but that has nothing to do with C++ treating a char as an int, that's purely down to the architecture. After all, it's just as quick to manipulate 32 bits as it is to manipulate 8 bits on a 32-bit system. On a 64-bit system, a single char will be treated as if it were 64 bits long (8 bytes) for the same reason.

User Avatar

Wiki User

10y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: C plus plus characters are internally treated as integers why?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

What is the difference between character '1' and integer 1 in terms of C plus plus?

Characters and integers are two different types: 'char' is an 8-bit unsigned integer (normally), while 'int' is a 16, 32 or 64-bit signed integer.Ints and chars are both integer numbers internally, but their numeric values are interpreted differently: The numeric value of the integer 1 is 1 (reasonably enough :), while the numeric value of the character '1' is 49.Characters are represented in computers by using a table mapping from integers to characters. The most common mapping is ASCII, and in the ASCII table the character 1 happens to have the numeric value 49. (I assume they didn't put it on 1 because all the values below 32 were reserved for system commands like 'bell' and 'escape'.)See related link for the ASCII table.


C plus plus file processing that will input 12 integers?

#include<iostream> #include<vector> int main() { std::vector<int> integers (12); for (size_t loop=0; loop<integers.size(); ++loop) cin >> integers[loop]; }


How do you print characters up and down in c plus plus vs. side to side?

Place a newline (linefeed) character ('\n') after each character you print. Depending on the device you may need a carriage return as well ('\r'). Usually the carriage return comes before the linefeed, but can often be treated as a string of two characters ("\r\n").


How are devices treated in C plus plus?

On some platforms (unix, for example) devices are handled as special files.


What are the conditions to swap in c plus plus without temporary?

You can swap two integers without temporary storage by bitwise exclusive-or'ing them in a specific sequence...a ^= b;b ^= a;a ^= b;

Related questions

Do you put a plus sign on positive integers?

no


What is the difference between character '1' and integer 1 in terms of C plus plus?

Characters and integers are two different types: 'char' is an 8-bit unsigned integer (normally), while 'int' is a 16, 32 or 64-bit signed integer.Ints and chars are both integer numbers internally, but their numeric values are interpreted differently: The numeric value of the integer 1 is 1 (reasonably enough :), while the numeric value of the character '1' is 49.Characters are represented in computers by using a table mapping from integers to characters. The most common mapping is ASCII, and in the ASCII table the character 1 happens to have the numeric value 49. (I assume they didn't put it on 1 because all the values below 32 were reserved for system commands like 'bell' and 'escape'.)See related link for the ASCII table.


-18 plus 20 equals integers?

Yes.


Is counting plus 0 called an integers?

Yes it is.


What is 3 plus 10 in adding integers?

13


Are plus 1 and -1 opposite integers?

0


What will happen if a char is counted as an int in C plus plus?

The main difference is that int values are treated as being integers whereas char values are treated as being character codes. Thus if you output a char with value 65 you will get the symbol 'A', but if you output an int with the value 65 you will get the value 65 instead. In order to output the symbol 'A' you would have to cast the int to a char.


What is the answer to -10 plus -7 plus -14 integers?

(-10) + (-7) + (-14) = -31


C plus plus file processing that will input 12 integers?

#include<iostream> #include<vector> int main() { std::vector<int> integers (12); for (size_t loop=0; loop<integers.size(); ++loop) cin >> integers[loop]; }


What is plus 49 plus -20 integers?

29


What is the multiplication table of integers from -10 to plus 9?

-9


If there are 2 integers and they both have to have a sum of -14 and plus 24 what are they?

Two integers can have only one sum, not two as required by the question.