GET EDUCATE

Contents
Basics of C Programming

⯈Basic C Programs

Character Representation in C

Characters, same as integers can be thought as value in circle. It goes from the minimum value 0 to maximum value 255 and reaches back 0. If we try to store the value greater than 255, overflow happens and the value reaches back 0.

character representation in C

Example:

char ch1 = 255;

char ch2 = ch1 + 1;

Mathematically, the value of ch2 will be 256, but we cannot store the value 256 in a character, integer overflow happens (since characters are stored as ASCII values) and the value of ch2 = 0.

Note: We can say in general that if value stored in char variable is 'x', then the effective value will be x % 256.

Example:

char ch = 356;

If we print the value at ch, it will be ‘d’ (ASCII value 100).

356 % 256 = 100

Scroll to Top