Why does a character constant require two bytes of memory space in C programming

Showing Answers 1 - 5 of 5 Answers

Farhanaaz

  • Dec 12th, 2006
 

 Because as characters are identified by ASCII values, ascii values are intergers. In c integers require require 2 bytes of memory to be stored

  Was this answer useful?  Yes

Rajeev

  • Jan 6th, 2007
 

in C constants will occupy 2 bytes minimum.so a char constant will occupy 2 bytes in which one byte is useless which is filled with zero's.

  Was this answer useful?  Yes

mprashant

  • Feb 19th, 2007
 

This is wrong one ..
please try this code as-

int main(){
printf("size of char const %dn",sizeof(const char));
getchar();
}

this prints
size of char const 1

abhimanipal

  • Jul 15th, 2009
 

int main()
{
  char c='A';
  const char a= 'C';
  printf("%dn",sizeof(c));
  printf("%dn",sizeof(a));

  return 0;
}

The output of this one is

1
1

  Was this answer useful?  Yes

kbjarnason

  • Jul 1st, 2010
 

They don't.

char a;  - a is a char variable, which requires one byte's storage.

'a' - 'a' is a character constant, which is of type _int_, which requires the same storage as an int... which can be 1, 2, 4, 16, 64, 512 or some other number of bytes.

In C, char and byte are equivalent in storage terms; one char equals one byte, storage-wise.  However, that can be anywhere from a (minimum) 8 bits wide to as wide as you'd like to go.  Several systems use 32 bit chars, shorts, ints and longs, for example, all of which take one byte, a 32-bit-wide byte.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions