将2个字符分配给int [英] Assign 2 char to an int

查看:132
本文介绍了将2个字符分配给int的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想了解此代码的结果:

I am trying to understand the outcome of this code:

#include<iostream>

using namespace std;

int main()
{
    int a = 'dd';
    cout << a;
    return 0;
}

结果是25700.编译器如何获得这个数字?
感谢

The result is 25700. How the compiler get this number? Thanks

推荐答案

'd'的ascii代码是0x64。 'dd'由编译器表示为0x6464,用十进制表示法时为25700.

The ascii code for 'd' is 0x64. The literal 'dd' was represented as 0x6464 by your compiler, which is 25700 when written in decimal notation.

这篇关于将2个字符分配给int的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆