Assigning multiple characters in an int in C language


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
", 'A');    printf("%d
", 'AA');    printf("%d
", '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.

Updated on: 30-Jul-2019

281 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements