C programming
character arithmetic
type conversion
ASCII values
data types

char char int? Why?

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

In C and similar languages, char + char usually produces an int, not a char. That surprises people because both operands started as characters, but arithmetic on small integer types follows the language's integer-promotion rules.

The short answer is: char values are promoted before arithmetic happens. By the time the addition runs, the operands are already being treated as int.

Characters Are Small Integers

A char stores a small integer value. It may represent a character code such as 'A', but inside the expression it is still a numeric type.

For example:

c
1#include <stdio.h>
2
3int main(void) {
4    char a = 'A';
5    char b = 1;
6    int result = a + b;
7
8    printf("%d\n", result);
9    printf("%c\n", result);
10    return 0;
11}

'A' has a numeric code, so adding 1 gives the next code point. The important part is that the result expression is computed as int.

Why Promotion Happens

C applies the integer promotions to types smaller than int before most arithmetic operations. That includes char and short.

This design avoids doing arithmetic in tiny types that may be awkward for the machine and helps standardize expression behavior across platforms.

So conceptually:

  • 'char becomes int'
  • the other char becomes int
  • addition happens as int + int

That is why the expression type is typically int.

What This Means in Practice

If you write:

c
char x = 'a';
char y = 'b';
printf("%d\n", x + y);

the printf argument is the integer sum of the promoted values, not a two-character string and not a char.

If you want the result back in a char, you must convert explicitly:

c
char next = (char)(x + 1);

That cast tells the compiler you are intentionally narrowing the arithmetic result back to a smaller type.

Watch Out for Overflow and Sign

Promotion does not remove every pitfall. A char may be signed or unsigned depending on the implementation, and converting an int result back to char can lose information.

So while promotion makes arithmetic more regular, narrowing back to char still deserves care.

This Is Not About ASCII Alone

People often explain this with ASCII examples, but ASCII is not the reason the promotion happens. The promotion rule is about C's arithmetic semantics, not about any particular character encoding.

ASCII examples are just convenient because letter codes are easy to visualize.

Assignment Is a Different Step

One reason this feels confusing is that expression type and assignment target are separate ideas. The addition is performed as int, but you can still assign the result to a char variable afterward. That assignment is a narrowing conversion step, and it may truncate or wrap depending on the value and implementation details.

Common Pitfalls

  • Thinking char + char should stay char because both operands started as characters.
  • Forgetting that printf with %d is showing the integer value after promotion.
  • Casting back to char without considering overflow or sign issues.
  • Assuming ASCII is the cause instead of the language's integer-promotion rules.
  • Treating character literals as if they were fundamentally different from small integers in expressions.

Summary

  • In C, char is a small integer type.
  • Before arithmetic, char operands are usually promoted to int.
  • That is why char + char yields an int expression.
  • Casting back to char is a separate, narrowing conversion.
  • The key concept is integer promotion, not ASCII itself.

Course illustration
Course illustration

All Rights Reserved.