C Character Data Types

C Tutorial

 C Character Data Types (Complete Guide: Beginner → Advanced)

In C language, the character data type is used to store single characters or small numeric values (ASCII codes).
It is 1 byte in size and is extremely important for strings, input/output, and low-level programming.


 What is a Character Data Type?

A character data type (char) stores one character at a time.

  •  Characters are stored internally as ASCII values

 Size of char

  •  Always 1 byte (8 bits)

ASCII Value Concept

Each character has a numeric ASCII code.

CharacterASCII
‘A’65
‘a’97
‘0’48
‘ ‘ (space)32

 Types of char in C

C provides three variations of character type:

char

  • Can be signed or unsigned (compiler dependent)

signed char

Range: −128 to 127

unsigned char

Range: 0 to 255


 Example: Signed vs Unsigned char


 

  •  Very important in embedded & system programming

 Character Input & Output

Input


 To skip whitespace:


Output


 Character Arithmetic


 

  •  Because characters are stored as numbers

char vs int (Important Difference)

Featurecharint
Size1 byte4 bytes
StoresCharacter / small numberLarge number
ASCII usageYesIndirect
  • char saves memory

char in Strings

  •  String = array of char
  •  Ends with '\0' (null character)

 Special Characters in char

  •  Used in formatting & string termination

char with <ctype.h> Functions


 

Common functions:

  • isalpha()

  • isdigit()

  • islower()

  • toupper()

  • tolower()


Common Mistakes

  •  Using double quotes "A" instead of 'A' 
  •  Forgetting & in scanf()
  •  Assuming char is always signed
  •  Confusing '0' and 0

 Interview Questions (Must Prepare)

  1. Size of char in C?

  2. Difference between char and unsigned char?

  3. What is ASCII?

  4. Output of char c = 65; printf("%c", c);

  5. Difference between 'A' and "A"?


 Real-Life Use Cases

  • String processing

  • Text files

  • Keyboard input

  • Embedded systems

  • Byte-level operations


Summary

  • char stores a single character
  •  Always 1 byte
  • Uses ASCII internally
  • signed & unsigned affect range
  •  Essential for strings, I/O & system programming

You may also like...