Home > Backend Development > C++ > body text

In C language, assign multiple characters to an int variable

WBOY
Release: 2023-08-27 23:53:03
forward
1360 people have browsed it

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;);
}
Copy after login

Output

65
16705
4276803
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template