How to find the size of a variable without using sizeof

后端 未结 10 1742
终归单人心
终归单人心 2020-12-17 06:07

Let us assume I have declared the variable \'i\' of certain datatype (might be int, char, float or double) ...

NOTE: Simply consider that \'i\' is

10条回答
  •  没有蜡笔的小新
    2020-12-17 06:33

    I hope that below code would solve your problem in c++ without using sizeof() operator

    for any variables like (int, char, float, double, char, short and many more...)

    here I take integer,

    int a;
    

    then show it as byte addressable output,

    cout<<(char *)(&a + 1) - (char *)(&a);
    

提交回复
热议问题