Home >Backend Development >C++ >In C language, assign multiple characters to an int variable

In C language, assign multiple characters to an int variable

WBOY
WBOYforward
2023-08-27 23:53:031381browse

In C language, assign multiple characters to an int variable

Character type data is stored internally in C or C by its ASCII value. If we want to print a single character as an integer, we will get the ASCII value. However, when we try to print multiple characters using single quotes, it prints some weird output.

Please check the following program to get the idea.

Example
#include <stdio.h>
int main() {
   printf("%d</p><p>", &#39;A&#39;);
   printf("%d</p><p>", &#39;AA&#39;);
   printf("%d</p><p>", &#39;ABC&#39;);
}

Output

65
16705
4276803

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

The above is the detailed content of In C language, assign multiple characters to an int variable. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete