Thread: size of char

  1. #1
    Registered User
    Join Date
    Sep 2011
    Posts
    28

    size of char

    What are limitations on size of char, are there any differences in c89 and c99 on size of char

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    It's always 1.


    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Sep 2011
    Posts
    28
    but can be larger than 8 bits(in both c89 and c99), right ?

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    It could be, but sizeof will always give you 1. You are interested in CHAR_BIT.


    Quzah.
    Hope is the first step on the road to disappointment.

  5. #5
    Third Eye Babkockdood's Avatar
    Join Date
    Apr 2010
    Posts
    352
    If you make an array of them, yeah. Try compiling and running this program.

    Code:
    #include <stdio.h>
    
    int main(void) {
        int x;
        printf("Size of char: %d\n", sizeof(char));
        for (x = 2; x < 10; x++)
            printf("Size of %d chars: %d\n", x, (sizeof(char) * x));
        return 0;
    }
    That should explain it best. The sizeof() operator returns the size of a variable or variable type in size_t. Take a look at these articles, if you're confused:

    sizeof - Wikipedia, the free encyclopedia
    For, While and Do While Loops in C - Cprogramming.com
    Cprogramming.com FAQ > Format output using printf() (C)
    Quote Originally Posted by The Jargon File
    Microsoft Windows - A thirty-two bit extension and graphical shell to a sixteen-bit patch to an eight-bit operating system originally coded for a four-bit microprocessor which was written by a two-bit company that can't stand one bit of competition.

  6. #6
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by Babkockdood View Post
    If you make an array of them, yeah.
    He's not talking about making an array. He's talking about the number of bits in a single char. I don't know why you included those other two links, because no one mentioned anything about either of those topics.


    Quzah.
    Hope is the first step on the road to disappointment.

  7. #7
    Registered User
    Join Date
    Sep 2011
    Posts
    28
    Quote Originally Posted by quzah View Post
    It could be, but sizeof will always give you 1. You are interested in CHAR_BIT.


    Quzah.
    Thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Change size of a char
    By ch4 in forum C Programming
    Replies: 6
    Last Post: 11-27-2009, 08:58 AM
  2. size of char **
    By gareth00 in forum C Programming
    Replies: 2
    Last Post: 10-28-2008, 12:49 AM
  3. size of <char>
    By abachler in forum C++ Programming
    Replies: 6
    Last Post: 04-25-2008, 05:09 PM
  4. What is the size of a char pointer?
    By someprogr in forum C Programming
    Replies: 6
    Last Post: 12-27-2007, 03:18 PM
  5. size of a char pointer (*)
    By Garfield in forum C Programming
    Replies: 14
    Last Post: 10-04-2001, 07:00 PM

Tags for this Thread