c++里面有没有什么办法做到 判断某个给定的未知数是double类型还是int类型 呢?

c++里面有没有什么办法做到 判断某个给定的未知数是double类型还是int类型 呢?

如果只是double和int, 可以用sizeof

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
using namespace std;
#include <stdlib.h>
int main()
{
    double a;
    double b;
    float c = 3.0;
      
     b=1, a=b+5/2;
    cout << sizeof a << endl;
    cout << sizeof b << endl;
    cout << sizeof  c<< endl;
    cout << sizeof 3 << endl;
    cout << sizeof 3.0 << endl;
    cout << sizeof((int)3)  << endl;
    cout << sizeof((long)3)  << endl;
    cout << sizeof((float)3)  << endl;
    cout << sizeof((double)3)  << endl; 
    system("pause");
    return 0;
}

c++里面有没有什么办法做到 判断某个给定的未知数是double类型还是int类型 呢?

c++里面有没有什么办法做到 判断某个给定的未知数是int类型,long类型,还是float类型 呢?

 貌似做不到

参考

--------------------------------
1.sizeof 运算符 - cppreference.com
2.若已定义x和y为double类型,则表达式:x=1,y=x+3/2的值是______.(A、1B、2C、2.0D、2.5_百度作业帮

== 以上 2017/7/7 下午3:00:20

原文链接: https://www.cnblogs.com/liango/p/7132257.html

欢迎关注

微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍

    c++里面有没有什么办法做到 判断某个给定的未知数是double类型还是int类型 呢?

原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/256480

非原创文章文中已经注明原地址,如有侵权,联系删除

关注公众号【高性能架构探索】,第一时间获取最新文章

转载文章受原作者版权保护。转载请注明原作者出处!

(0)
上一篇 2023年2月14日 上午10:06
下一篇 2023年2月14日 上午10:06

相关推荐