-2
$\begingroup$

the size of one char in C is 4 bytes, however to define an 'A' character we use the sum of two values like this expression here:

Text

or in other way i want to say that the char is 4 bytes size, but in the example it shows that the size is 8 bytes.

how it happens, what is wrong here ?

$\endgroup$
8
  • 2
    $\begingroup$ Size of char in C is 1 byte or 8 bits. $\endgroup$ Aug 24 '21 at 20:12
  • $\begingroup$ You can check the size of character data type in C using sizeof(char) which shall return the size of a data type in bytes. You shall get the answer as 1. The polynomial which you have written is nothing but the decimal conversion of the 8 bit binary number 01000001 which 65 in decimal and this happens to be the ASCII code of the character A $\endgroup$ Aug 24 '21 at 20:17
  • $\begingroup$ ASCII is a standard code for character representation, where the least significant 7 bits are used to represent character. giving a total of 128 characters while the most significant bit is used for parity... $\endgroup$ Aug 24 '21 at 20:19
  • $\begingroup$ @AbhishekGhosh Size of char in C is at least 8 bits. $\endgroup$
    – Pseudonym
    Aug 25 '21 at 5:36
  • $\begingroup$ With emphasis on at least which means it can be more. Like 12, 16 or 32. $\endgroup$
    – gnasher729
    Aug 25 '21 at 6:24
1
$\begingroup$

Sizeof(char) = sizeof(unsigned char) = sizeof(signed char) = 1 by definition in C and C++. And char contains at least 8 bit (it can be more, but 8 is by far the most common).

So your assumption that the size of one char in C is 4 is wrong. However, in C a character literal like 'x' has type int, not type char, so sizeof('x') = sizeof(int) is usually larger than 1, and 4 is not unusual but in no way guaranteed.

Your calculation doesn’t show that sizeof(char) would be 8 in any way, because you confused “bit” and “byte”.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.