Char to Int

Is char Always 1 Byte in C?

Yes, sizeof(char) is always 1 in C. The number of bits in that byte is set by CHAR_BIT, which is 8 on most systems. Here is what that means in practice.

On this page
  1. Short answer
  2. What sizeof(char) means
  3. How many bits a byte has
  4. A char is not always one character of text
  5. Other sizes that vary
  6. Checking the sizes on your system

Short answer

Yes. In C, sizeof(char) is always 1. The size of a char is the unit that sizeof counts in. What is not fixed is how many bits make up that unit. The number of bits is set by CHAR_BIT, and on most current systems it is 8.

What sizeof(char) means

The C standard says that sizeof applied to a char, signed char, or unsigned char gives 1. So sizeof(char) is 1 on every conforming system, whatever the hardware. The C++ standard gives the same rule.

#include <stdio.h>

int main(void) {
    printf("sizeof(char) = %zu\n", sizeof(char));  // always 1
    return 0;
}

The %zu format is for size_t, the type that sizeof returns.

How many bits a byte has

The number of bits in a char is given by CHAR_BIT. It is defined in <limits.h> in C and in <climits> in C++. The standard requires at least 8 bits. Most common desktop, server, and mobile systems use 8, but a platform is allowed to use more.

So in C, one byte is the size of one char. On most systems that is 8 bits, but the standard does not fix it at exactly 8.

A char is not always one character of text

A char holds one code unit, which is not always one visible character. In UTF-8, the letter é is stored as two bytes, so it takes two char values. A string that looks short on screen can have more char values than it has letters.

Because of this, the length of a string in char values is not always the number of characters a reader sees.

Other sizes that vary

Some related sizes depend on the platform:

  • int is not always 4 bytes. Four bytes is common on mainstream systems, but the standard sets only minimum ranges for int. If your code depends on the size of int, check it with sizeof instead of assuming four bytes.
  • wchar_t is used for wide characters, and its size depends on the platform.
  • Whether plain char is signed or unsigned depends on the compiler. signed vs unsigned in c explains what that changes.

The sizes of the other basic types are listed in primitive data types in c. How sizeof itself works is covered in sizeof function in c.

Checking the sizes on your system

This program prints three sizes. The values can differ from one system to another:

#include <stdio.h>
#include <limits.h>

int main(void) {
    printf("sizeof(char) = %zu\n", sizeof(char));
    printf("CHAR_BIT     = %d\n", CHAR_BIT);
    printf("sizeof(int)  = %zu\n", sizeof(int));
    return 0;
}

On many common desktop systems, the output is 1, 8, and 4. The first line always shows 1. The other two depend on the platform. A character’s numeric code is a separate topic, covered in c char to int.

The complete guide to char to int

How to Convert a Char to an Int in C++
Read the guide

Keep exploring

Guides from other topics

All topics →

What Is long long in C++?

long long is a C++ integer type at least 64 bits wide. Learn its range, how to declare and print it, and when to use it instead of int, with examples.

long long 5 min read