Assigning multiple characters in an int in C language

CServer Side ProgrammingProgramming

The character type data is stored by its ASCII value internally in C or C++. If we want to print a single character as integer, we will get the ASCII value. But when we are trying to print more than one character using a single quote, then it will print some strange output.

Please check the following program to get the idea.

Example

#include <stdio.h>
int main() {
   printf("%d\n", 'A');
   printf("%d\n", 'AA');
   printf("%d\n", 'ABC');
}

Output

65
16705
4276803

The ASCII of A is 65. So at first it is showing 65 (01000001). Now for AA, it is showing 16705. This is ASCII of 6565 (01000001 01000001) = 16705. For third the value is ABC (01000001 01000010 01000011) = 4276803.

raja
Published on 26-Apr-2019 13:05:19
Advertisements